Linux Commands

Command Description
General Commands
clear Clears the Linux/Unix terminal screen
date Displays the system date and time
cal It Displays calander
type Tells about type of command (whether internal or external)
alias Creates alias of existing command
pwd Shows your current working directory
man Shows various options associated with a particular command
who Display the user details who is currently login
File and Directory related Commands
touch Creates the empty file(s) if it does not exist,
Otherwise change the timestamp of file
cat 1.creates the file and save the content
2.Display the file contents
3.Append the content in existing file
file Displays wether its file or directory
more Pagewise display with %
less Pagewise display without %
mkdir Creates the new directory
cd To change the directory
rm To remove or delete the files / directories
rmdir To remove a empty directory
ls To list all files and directories of target directory
cp Copy file(s) from source to destination
mv Move the file(s) from source to destination
ln To make hard or soft link netween the files
Text Processing Commands
paste To combine the content of file files line by line and printing the files content horizontally
wc Displays the no of lines words and characters of any data
head Displays the lines from top to bottom as per option given
tail Displays the lines from bottom to top as per option given
cut Used to retrieves specific characters or fields from data or file
tr Used on out put of some other command to translate characters
sort Used to sort data, by default sorting happens as per the English disctionary
grep Used to pattern search in the given file
uniq Removes adjacent repeated lines in given data of file
cmp Used to compare two files, Its pinpoints at only first diffrence
comm Used to compare two files but can be apply only on sorted files
Process and Memory Related Commands
ps Displays the list of process submitted to kernel
pstree Displays the process in the form of tree diagram
bg Displays the status of process running in background
fg Used to bring any background job in foreground
nice Execute a command with updated scheduling priority
kill Used to send signal to perticular process
nohup Execute the command in background even after user get log out
df Print the system disk space usage and available
du Estimate file space usage in current directory
Compression Utilities Commands
gzip -To compress and decompress the file(s)
-Compressed file(s) gets .gz extension
gunzip Used to decompress the file having extension of .gz
Works same as gzip -d file.gz
zip -Use to compress file(s) to avoid compatibility problemsand with non-Linux users.
unzip -To extract the contents of a zip file.
zcat Displays the contents of compressed files
zmore Used to view content pagewise of compressed file
tar -Used to create a tape archive file
-Extract from archive file
Find Command
Find is one of the powerful utility of Unix/Linux used for searching the files or group
of in a directory hierarchy.

Syntax :
     $ find [pathname] [expression]
Examples on the find utility :

1). How to find file 'abc.txt' from home directory downwards and print them ?
$ find ~ -name abc.txt -print
or
$ find  ~  –type  f  –name  abc.txt  –print
2). How to find which ends with any digits and begin with 'abc' from home
   directory downwards and print them ?
$ find ~ -name "abc[0-9]" -print
3). How to find a directory name 'dirname' from home directory downwards and 
      print them ?
$ find ~ -type d -name dirname -print
4). How to search a character special file 'abc.txt' from current directory ?
$ find . -type c -name abc.txt -print
5). How to find file in current directory , which has inode value 76538 ?
$ find . –inum 76538 –print
6). How to find all files from current directory , which have 2 links ?
$ find . –links 2 –print
7). How to find all files from current directory , which have more than 2 links ?
$ find . –links  +2 –print
8). How to find all files from current directory , which have less than 4 links ?
$ find . –links  -4 –print
9). How to find all files from home directory downwards, which have permissions 
      755 ?
$ find ~ –perm 755 –print
10). How to search a block special file ‘abc.txt’ from home directory downwards
       and print them?
$ find  ~  –type  b  –name  abc.txt  –print
11). How to search a file ‘abc.txt’ from home directory downwards whose owner
       is ‘mukesh’ ?
$ find ~ \( –user mukesh –a –name abc.txt \) –print
12). How to search all files from home directory downwards, which have size
      1 MB
$ find ~ –size 1M –print
13). How to search a file 'file.txt' from current directory downwards and execute 
       'rm' command  on the result ?
$ find . –name file.txt –exec rm {} \;
14). How to search a file 'file.txt' from current directory  and execute 'rm'
       command on the result after confirmation ?
$ find . –name file.txt –ok rm {} \;
  ( or )
$ find  .  –name file.txt –exec rm –i {} \;
15). How to search the file 'abc.txt' in the current directory and three levels down
to the current directory ?
$ find -maxdepth 4 -name "abc.txt"
16). How to print the files in the sub-directories between level 1 and 5 ?
$ find -mindepth 2 -maxdepth 6 -name "abc.txt"
17). How to find the empty files in current directory?
$ find . maxdepth 1 -empty
18). How to find all files in current directory?
find . -maxdepth 1 -type f
Communication Commands
write command
Send a message to another user who is logged in.

Syntax
$ write <user_name>

Example
mithun.s@mks-laptop:~$ write mukesh.kumar

write: mukesh.kumar is logged in more than once; writing to pts/0
hi mukesh ,how are you ?

in above command mithun.s sending message to mukesh.kumar as 'hi mukesh ,how are you ?'

Now mukesh.kumar will get this on his terminal as below
mukesh.kumar@mks-laptop:~$

Message from mithun.s@mks-laptop on pts/2 at 13:32 ...
hi mukesh

mesg command
allow and disallow to other user to send message to you.

Syntax
$ mesg y[or n]

Example
$ mesg  -- Displays the status as below
is y

Disallow other users to send you message.
$ mesg n
$ mesg     -- Now it displays the status as below
is n

To allow other users to send you message type
$ mesg y

Note : Even if user disables the message he/she would receive the messages from the root.

wall command
Send a message to all the logged in user who having message recieving permission as yes.

Syntax
$ wall [-n] [-t TIMEOUT] [file]

-n : no banner
-t : timeout ,default time out is 300 sec

Example
$ wall hello world

Broadcast message from root (pts/1) (Thu Feb 27 15:06:04 IST 2014):
hello world

ftp command
Ftp (File Transfer Protocol) is the user interface to the Internet standard File Transfer Protocol.
The program allows a user to transfer files to and from a remote network site.

Syntax 
$ ftp [hostname]

put command
to copy one file from the local machine to the remote machine
$ put filename

get command
To copy one file from the remote machine to the local machine
$ get filename

To copy multiple files from the local machine to the remote machine;
 you are prompted for a y/n answer before transferring each file
$ mput file1 [file2...]

copy all from the local machine to the remote machine,which are starting from 'f'.
$ mput f*

To copy multiple files from the remote machine to the local machine;
 you are prompted for a y/n answer before transferring each file
$ mget file1 [file2...]

To copy all files from remote machine to the local machine which are starting from 'f'.
$ mget f*

To exit the FTP environment (same as quit)
$ bye

To terminate a connection with another computer
System will give “Good Bye” message then type bye
$ close

To request a list of all available FTP commands
$ help or $ ?

User can also type ‘?’ symbol for to list all FTP command
![Command]
Syntax
$ ![Command [arg...]]

Used to execute any command in local machine
It shifts the control from ftp prompt to local machine

$ !

This will shift the control from ftp prompt to local machine. Now user can perform any operation in local system by using the command prompt.
To shift the control back to ftp prompt, use exit command.



                                                     Commands in detail                
Clear Command
It will clear your linux/unix terminal screen
$ clear

date command
To display the system date and time ,it will give the below output
$ date
Fri Feb 21 00:56:30 IST 2014

cal command
 1.To display the calendar for current month
 $ cal

 2. To display the calendar for Jan month(month value 01) for 2014
 $ cal 01 2014

 3. To display the complete calendar of year 2007
 $ cal 2007

Type command
 To check whether clear command is internal or external
 $ type clear
  clear is /usr/bin/clear

 Above command showing one path in output, means it is stored as a file, so clear is
 external command.

 Now let us check whether alias command is internal or external
 $ type alias

 alias is a shell builtin

 It is displaying the message “alias is a shell built-in”, so alias is internal command.
 alias Command
 To create alias name of an existing command
  $ alias c=clear

 now you can use only command 'c' instead of clear ,but its scope remain for the
 current  terminal

Who command
To display the details of all users who are currently logged in
$ who          --  Displays the self details as below

mukesh.kumar tty7         2014-02-26 19:26 (:0)
mukesh.kumar pts/0        2014-02-26 23:24 (:0.0)
$ who i am
O/P: mukesh.kumar pts/5        2014-02-24 17:43 (:0.0)

man command
This command can be use to find the various option associated with particular command.
Syntax  :
 man <command name>

To see the various option associated with who command on terminal type below command
$ man who

pwd command
This command will show your present working directory.
$ pwd -- will show as below
/home/mukesh.kumar/Desktop/Ayush_patient_data

touch command
Used to create the empty file ,it is also used to change the timestamp of existing files
Syntax
$ touch [option] file_name(s)

Examples
To create multiple empty file at a time ,type below command
$ touch file1 file2 file3 file4

To change both the access and modification times to the current time of existing file file1
$ touch -am file1

To use the times of file1 for file2, use oprion -r(reference) as below
$ touch -r file1 file2

The -d and -t options allow the user to add a specific last access time, to change the last access time of file1 to 10 Mar 2014 09:30 would be enclosed in single quotes
and used as follows
$ touch -d '1 Mar 2014 09:30' file1

cat command
Cat can be used for the following purpose
1.To reading or display the content of file
2.New file creation
Syntax
$ cat [option] [filename]

Examples
To reading or display content of file1 ,write below command
$ cat file1

To display the content of more than one files
$ cat file.txt abc.txt f1.txt

The above command will display the content of files in same order ,first it will show the content of file.txt then below that abc.txt then in last f1.txt

To create a new file and writing some content in file.
$ cat > file1.txt
  ----
  ----
 ctr+d (to save all content in file1.txt)

Note : if file1.txt already exist then new data will get override.

To append the data in existing file
$ cat >> file1.txt
  ----
  ----
 write some data and hit 'ctr+d' to save the file1.txt

file command
To check type of file ie: whether it is file or directory.
Syntax
$ file [option] [file/dirname]

more command
To display page wise ,useful when file having more pages which can not be display at a time on the computer screen.
The more command allow you to reading the content from page1
$ more file1.txt

less command
Similar to more command.
This command allows you to view a text file without fear of accidently modifying it, as you would with a text editor
$ less file1.txt

mkdir command
Creates the directory in the current directory, if they do not already exist.
Syntax
$ mkdir [option] [dirname]

Examples
To create a directory dir1 in current directory
$ mkdir dir1

To create a dir in a path ,suppose i would like to create a directory dir2 inside another directory name 'freelancer'
Then we need to give the path of the directory 'freelancer' followed by new directory 'dir2' as follow
$ mkdir /home/mukesh.kumar/Desktop/freelancer/dir2
       (or)
--in general

$ mkdir path/dir2

To create the hierarchy of directories ,use -p(parents) option
$ mkdir –p dir1/dir2/dir3

cd command
To change the shell working directory
Following command will change current directory to dirname if dirname is present in current directory
$ cd dirname

To change the directory in the mentioned path
$ cd path/dir1

To changes to the home directory
$ cd (or) $ cd ~

To changes to the root directory (i.e. />)
$ cd /

To changes to the Parent directory
$ cd ..

rm command 
Used to delete the file or directory.
Syntax
rm [option] [-r directories] [filename]

Examples
To remove multiple files
$ rm file1 file2 file3 [file4..]

To remove a directory recursively
$ rm -r dirname

To remove file interactively
$ rm -i filename.txt

rm: remove regular file `filename.txt'?

Note : if rm command used by using '-i' option it will always ask user to confirm by displaying a message.

Removing forcefully
Assume filename is not having write permission for the user. If the user is giving the below command
$ rm filename

It will display confirmation message before removing the file.
But if user is giving the command with ‘-f’ option as follows:
$ rm –f file_name

It will remove the file forcefully without displaying confirmation message

To remove a file whose name starts with a `-', for example `-foo',
use one of these commands:
$ rm -- -foo
   (or)
$ rm ./-foo

rmdir command
rmdir can be use to remove the empty directory
$ rmdir emptydir

ls (list) command
List information about the FILEs (the current directory by default).
Syntax
$ ls [option] [file]

Note : To check the various option ,use the following command
$ ls --help

Examples
To list all file and directories of current directory
$ ls

To list files and directories of target directory in long format
(includes accesspermissions, size of file, last modification date & time, no of links etc.)
$ ls -l

To list files and directories of target directory
$ ls dirname

To list all the files and directories (including hidden) of target directory
$ ls -a dirname

To list files and directories of target directory in reverse order.
$ ls -r dirname

Note : by default it shows in alphabetically.
To list files and directories of target directory with their inode value.
$ ls -i dirname

To list all the files and directories of target directory recursively
$ ls -R dirname

To list files and directories of target directory with information of format of file
(ie : directory name with ‘/’ as suffix, executable files with ‘*’ as suffix etc.)
$ ls -F dirname

To list with inode value
$ ls -i dirname

To list all the files and directories(including hidden files) of target directory in long format
$ ls -al dirname

To list files and directories with inode values recursively of target directory in long format
$ ls -iRl dirname

To list files and directories with last modified in reverse order
$ ls -ltr dirname

cp command 
To copy files and directories from source to destination.
Synatx
$ cp [option] source destination

Examples
To create copy of file1.txt with name file2.txt in same directory
$ cp file1.txt file2.txt

To create copy of multiple source file(s) with same name in source directory
$ cp file1.txt [file2.txt] dirname

To copy dir1 or content of dir1 in dir2
$ cp -r dir1 dir2

Note : if dir2 is not present : create dir2 in current dir,copy content of dir1 in dir2
            if dir2 present : COPY sub tree structure rooted at dir1 in dir2
           ( inside dir2 we will get dir1)

To copy files interactively. It will ask for confirmation by displaying a message to the user but only in the case of overwriting.
$ cp –i source destination

mv command
Used to rename source file/directory to destination name
Move source file/directory to destination directory
Syntax
$ mv [option] source destination

To rename source file with destination name
$ mv file1.txt file2.txt

To move source files in destination directory
$ mv file1.txt [file2.txt] dirname

To move dir1 or content of dir1 into dir2
$ mv -r dir1 dir2

Note : if dir2 is not present :rename dir1 with name dir2
           if dir2 present then move sub tree structure rooted at dir1 in dir2
To Move or rename interactively. It will ask for confirmation by displaying a message to the user but only in the case of overwriting.

$ mv –i source destination

ln( link ) command 
To create hard and soft link between the files
There are two types of link we can create

1.Hard Link :
While creating a link from source to Destination file.The changes done in the source file will be effected in destination file.
But when The source file is deleted the destination file remains the same.

2.Soft Link :
While creating a link using soft link from source to destination file → the changes done
in the source file will be effected in Destination file too.
But when the source file is deleted the destination file also gets invisible. i.e when u tried to check the destination file its says no such file or directory

To make hard link between the file
$ ln sourcefile destinationfile

To makes soft(or symbolic) link between files
$ ln -s source destination


Note : we can not create hard link for directory

paste command
Used to combine 2 or more files content line by line and display the files content horizontally
Syntax
$ paste file1.txt [file2.txt..]

wc command
Used to display the no of lines,words and characters in any file or in any data.
syntax
$ wc [-lwc] filename.txt

head command
Used to display the set of lines from start in given file or data.
Syntax
$ head [-n] filename.txt

tail command
Used to display the set of lines from end of given file or data.
Syntax
$ tail [-n] filename.txt

Examples on head and tail commands
consider file1.txt having 15 lines as showing below
$ cat file1.txt

 1    One
 2    Two
 3    Three
 4    Four
 5    Five
 6    Six
 7    Seven
 8    Eight
 9    Nine
10    Ten
11    Eleven
12    Twelve
13    Thirteen
14    Fourteen
15    Fifteen

To print first 10 lines from top
$ head file1.txt
    (or)
$ head -10 file1.txt

Note : If count is not specified in command ,then by default it will take first 10 lines

To print the first 7 lines
$ head -7 file1.txt>
     (or)
$ head file1.txt -n 7

To print 10 lines from bottom
$ tail file1.txt
    (or)
$ tail -10 file1.txt

Note : If count is not specified in command ,then by default tail command will
take 10 lines from bottom

To print the 7 lines from bottom
$ tail -7 file1.txt
     (or)
$ tail file1.txt -n 7

To print the lines from line no 3 to 8
$ head -8 file1.txt | tail -6

cut command :
Used to retreive specific fields or characters from a file or data, it is used on output
of some other command
Syntax
$ cut [option] [filename]

Examples
Consider a file name file3.txt having content as following
$ cat > file3.txt

hello how are you!
one two three four

To retrieve the 7th character
$ cat file3.txt | cut -c7

To retrieve a character set from 5th to 9th character
$ cat file3.txt | cut -c5-9    

To retrieve 5th and 9th character
$ cat file3.txt | cut -c5,9

We can pipe cut command on any command like date ie:
$ date | cut -c7

$ date | cut -c5-9

To cut the 4th field delimated by spaces
$ date | cut -d "" -f4

To cut the 4th to 6th field delimated by space
$ date | cut -d "" -f4-6

To cut the 4th and 6th field delimated by space
$ date | cut -d "" -f4,6>
   
$ cat file3.txt | cut -d "" -f4,6

Note :
-c : for character number
-d : for delimiter (either space,comma,colon etc)
-f : for field number

tr (translate) command
Used to translate characters, by pipe on some other command
Syntax
$ tr [option] SET1 SET2

Examples
To squeezing character or remove the extra spaces between words
type tr -s " " on output of command ie :
The output of command 'who am i' having extra space as
$ who am i
mukesh.kumar pts/4        2014-03-12 16:08 (:0.0)

The following command will squeeze the words or remove the extra spaces
$ who am i | tr -s " "
mukesh.kumar pts/4 2014-03-12 16:08 (:0.0)

Translating the character without squeezing
$ who am i | tr " " "$"

Squeezing and then translation
$ who am i | tr -s " " "$"

tr Command examples:
Consider file2.txt having the below content
$ cat file2.txt

Hi       Friends
Hello      World
How are    you      !
Lets        learn the    commands

To remove the extra spaces or squeezing the space character
$ cat file2.txt | tr -s " "
output:
Hi Friends
Hello World
How are you !
Lets learn the commands

Squeezing space and translating the space to '$' character
$ cat file2.txt | tr -s " " "$"
output:
Hi$Friends
Hello$World
How$are$you$!
Lets$learn$the$commands

Translating the spaces without squeezing
$ cat file2.txt | tr  " " "$"
output:
Hi$$$$$$$Friends
Hello$$$$$$World
How$are$$$$you$$$$$$!
Lets$$$$$$$$learn$the$$$$commands

To convert the lower case into upper case letter
$ cat file2.txt | tr  "[a-z]" "[A-Z]"
output:
HI       FRIENDS
HELLO      WORLD
HOW ARE    YOU      !
LETS        LEARN THE    COMMANDS

Translating all character 'H' or 'h' to '#'
$ cat file2.txt | tr  '[H,h]' '#'
output:
#i       Friends
#ello      World
#ow are    you      !
Lets        learn t#e    commands

sort command
Used to sort the data by default it sorts as per the english disctionary
It used on output of some other command or file content
Syntax
$ sort [option] [filename]

Examples
To sort as per the english disctionary
$ sort file.txt

To sort in reverse order
$ sort -r file.txt

To apply the numerical sort
$ sort -n file.txt

To remove all duplicate recards in file or data
$ sort -u file.txt

To merge the content of two or more file in sorted manner
$ sort -m file1.txt file2.txt

Note:
If using -m option with sort command, file1.txt file2.txt should be in sorted order.
If the supplied arguments files(file1.txt, file2.txt) are not in sorted order then we should
use only 'sort' instead of 'sort –m'.

Consider the following data in student.txt, in which the first column is student id ,
2nd column is marks and 3rd is subject.
$ cat student.txt

2001:90:Math
2002:60:Physics
2003:75:Chemistry
2004:84:Math
2005:94:Chemistry
2006:96:Math
2007:86:Physics
2008:91:Physics
2009:89:Physics

Sorting based on the second column, delimated by colon
$ sort -k2 -t ":" student.txt
       (or)
$ sort +1 –t ":" student.txt
output:
2002:60:Physics
2003:75:Chemistry
2004:84:Math
2007:86:Physics
2009:89:Physics
2001:90:Math
2008:91:Physics
2005:94:Chemistry
2006:96:Math

Sorting based on the 3rd column, delimated by colon
$ sort -k3 -t ":" student.txt
       (or)
$ sort +2 –t ":" student.txt
output:
2003:75:Chemistry
2005:94:Chemistry
2001:90:Math
2004:84:Math
2006:96:Math
2002:60:Physics
2007:86:Physics
2008:91:Physics
2009:89:Physics

To store the final merged data into onother one file
$ sort –m file1.txt file2.txt –o output

grep command
Used to search for PATTERN in each FILE or standard input.
Syntax
$ grep [OPTION]... PATTERN [FILE]

Examples
To search the pattern 'Linux' in file1.txt
$ grep Linux file.txt

To search the pattern 'Linux' in multiple files say file1.txt,file2.txt,file3.txt
$ grep Linux file1.txt file2.txt file3.txt

To search for sequence of strings, including phrases
$ grep 'hello world' file1.txt file2.txt file3.txt

To ignore case while searching , use option '-i'
$ grep -i linux file.txt

To print the count of lines which having pattern 'linux'
$ grep -c linux file.txt

To print the lines which are not having pattern 'linux'
$ grep -v pattern file.txt

To search pattern for all txt files in current directory
$ grep 'linux is' *

To print the line numbers with each output lines ,where given pattern 'linux' found
$ grep –n linux file.txt

To print only the name of the files where pattern 'linux' is matching
$ grep –l linux file1 file2 file3

Some more useful grep command:
To prints lines containing any character
$ grep '.' filename.txt

To prints lines containing period character
$ grep '\.' filename.txt

To prints blank lines or lines not containing any character.
$ grep –v '.' filename.txt

To print line starting with any pattern
$ grep '^pattern' filename.txt

To print line ending with any pattern
$ grep 'pattern$' filename.txt

Examples in which defining sone boundry of words
To print the lines which are containing words starting with pattern 'linux'
$ grep '\<linux' filename.txt

To print the lines which are containing words ending with pattern 'linux'
$ grep 'linux\>' filename.txt

To print the lines which are containing given pattern 'linux' as a whole words
$ grep '\<linux\>' filename.txt

uniq command
To removes adjacent repeated lines in the given data or files
Syntax
$ uniq [OPTION]... [INPUT [OUTPUT]]

Examples
consider the file as file4.txt which containing following data
cat file4.txt

math
physics
physics
chemistry
linux
math
math
window

To removes adjacent repeated lines in the given data or files
$ uniq file4.txt
output:
math
physics
chemistry
linux
math
window

To print only adjustant duplicate lines
$ uniq -d file4.txt
output:
physics
math

To print only uniq lines which is not adjustant duplicate
$ uniq -u file4.txt
output:
math
chemistry
linux
windo

To display the line count of occurrences of line adjustant duplicate
$ uniq -c file4.txt
Output:
      1 math
      2 physics
      1 chemistry
      1 linux
      2 math
      1 window

cmp command
Used to compare two files byte by byte ,its pinpoints only the first diffresnce between two files
Syntax
$ cmp file1.txt file2.txt

Consider the content of file1.txt
$ cat file1.txt

john
monty
hi
linux
bye

Consider the content of file2.txt
$ cat file2.txt

john
monty
hi
unix
bye

Now on comparing the both the file
$ cmp file1.txt file2.txt
output:
file1.txt file2.txt differ: byte 15, line 4

The above command is comparing both the files and only giving first difference at line no 4.

comm command
Used to compare sorted files FILE1 and FILE2 line by line.
Syntax
$ comm [OPTION]... FILE1 FILE2


comm command gives the output in 3 columns
 1.data uniq in first file
 2.data uniq in second file
 3.data common in both files

To use comm command both the files should be in sorted manner.
To sort the file1.txt and storing the result in file10.txt
$ sort file1.txt > file10.txt

To sort the file2.txt and storing the result in file20.txt
$ sort file2.txt > file20.txt

Now on using the 'comm' command on sorted files as following
$ comm file10.txt file20.txt
output :
bye
hi
john
  linux
monty
unix




                Process related command
ps command
To see the list of processes submitted to kernel
Syntax
$ ps [option..]

To see full listing with PPID and including user and system process.
$ ps -ef

where :
-e to display all the processes.
-f to display full format listing.

To see every process with PPD and user on the system using BSD syntax:
$ ps -awx (or)  ps awx

where :
-a,a  all w/ tty, including other users
-w,w  wide output
-x,x  processes w/o controlling ttys

pstree command
To see the process in the form of tree diagram.
Syntax :
$ pstree [options] [pid or username]

To see the tree diagram with process identification numbers (PIDs)
$ pstree -p

We can use more or less command along with pstree to see pagewise view
$ pstree | less (or)  pstree | more

To see only those branches that have been initiated by a user with a username mukesh
$ pstree mukesh

bg command 
It can be used to see the status of jobs which are running in the background.
$ bg

fg command
To bring the job in foreground from background by its JobId or PID
Syntax
$ fg %JobID (or)  fg #PID

Some examples on background and foreground processes:
Below command will execute the process created by the shell in foreground and the output is redirecting in file1.
$ ls -laFrR > file1

To send the above process in the background add one symbol '&' at the end of command.
$ ls -laFrR > file1 &

[1] 3951

The value 1 written in square bracket is JobID for this job and 3951 is PID for this process.

Immediate after running above command we can check the status of this background processes.
$ bg

bash: bg: job 1 already in background

Once this background process get over , the status will be like below
$ bg

bash: bg: current: no such job

To bring this job in foreground, use the following command
$ fg %1      (or)      fg #3951

nice command
Use nice command to run a program with modified scheduling priority
Nicenesses range at least from -20 (resulting in the most favorable scheduling) through 19 (the least favorable). The default behavior is to increase the
niceness by 10.
Syntax
$ nice [option][command]

Examples on nice command
To see the current scheduling inherited priority
$ nice

Below command will execute ls command with incremented scheduling priority. Here we are not giving any adjustment to priority, so by default priority
is incremented by 10.
$ nice  ls

To increase the scheduling priority by 5
$ nice –n5 ls

kill command
Kill sends signal to the process having with process ID as pid. If no option is specified,it sends default signal 15 (software termination signal) to the process.
Syntax
$ kill [signal] PID

Where :
Option - 1   Hang-up signal.
Option - 2   Interrupt signal.
Option - 9   terminate the process.
Option -15   Software termination signal.

Example: 
$ kill  -9  3951

Rules on the kill command
1.You can kill all your own process.
2.Only root user can kill system level process.
3.Only root user can kill process started by other users.

nohup command
nohup command allows to run command/process or shell script that can continue running in the background after you log out from a shell
Syntax:
$ nohup <commandname/shells-script>
(or)
$ nohup <commandname/shells-script> &

Example: 
$ nohup txncleanup.sh  &

Memory related command
df command
Report the amount of disk space being used by file systems,If no file name is given, the space available on all currently mounted file systems is shown.
Syntax
$ df [option] [file_name]

Type the below command to see variaous option which can be used along with df
$ df --help

Example :
To display all file systems and their disk usage
$ df

output:
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1            150900956  94750776  48484824  67% /
none                    504780       280    504500   1% /dev
none                    509024      2164    506860   1% /dev/shm
none                    509024       208    508816   1% /var/run
none                    509024         0    509024   0% /var/lock
none                    509024         0    509024   0% /lib/init/rw

To display above command in human readable format
$ df -h

output:
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             144G   91G   47G  67% /
none                  493M  280K  493M   1% /dev
none                  498M  2.1M  495M   1% /dev/shm
none                  498M  208K  497M   1% /var/run
none                  498M     0  498M   0% /var/lock
none                  498M     0  498M   0% /lib/init/rw

du command
du estimates and displays the disk space used by files.
Summarize disk usage of each FILE, recursively for directories.
Syntax
$ du [option] [filename]

$ du [option] --files0-from=F

Example
To display the size of each files starting from 'f' in current directory.
$ du -sh f*

Type the below command to see variaous option which can be used along with du
$ du --help

gzip command
This command can be use to compress and decompress the file(s), the compressed file(s) have .gz extension.
To compress the file(s) use
$ gzip file1.ext [file2.txt...]

To decompress back,compressed file(s)
$ gzip -d file1.ext.gz [ file2.txt.gz...]

gunzip command
It is same as 'gzip -d', use to decompress the file(s) having extension .gz
$ gunzip file1.ext.gz

zip commmand
If you exchange file(s) with non-Linux users,then you can use zip to avoid compatibility problems. Red Hat Linux can easily open zip or gzip files,
but non-Linux operating systems may have problems with gzip files.

To compress a file with zip, type the below command :
$ zip -r filename.zip files

In this example, filename represents the file you are creating and files represents the files you want to put in the new file:

unzip command
To extract the contents of a zip file, type:
$ unzip filename.zip

You can zip or gzip multiple files at the same time as following example
gzip filename.gz file1 file2 file3 /user/work/college
The above command will compress file1, file2, file3, and the contents of the /user/work/college directory and put them in filename.gz.

zcat command
If you try to view a compressed file using 'cat filename' , it wont show the readable content.
Hence zcat command can be use to view the content of compressed file properly.
$ zcat file1.txt.gz

zmore command
Use to view page wised of a compressed file.
$ zmore file1.txt.gz

tar command
Tar files place several files or the contents of a directory or directories in one file. This is a good way to create backups and archives.
Usually, tar files end with the .tar extension.
TO create a tape archive file
$ tar -cvf filename.tar files/directories

In this example, filename.tar represents the file you are creating and files/directories represents the files or directories you want to put in the new
file.
To extract the contents of a tar file, type:
$ tar -xvf filename.tar

Note :
If any of the files  are directories, tar  acts on the entire subtree. Options need not be preceded by -.
Function Options (choose one)
c - create a new tape
v - verbose mode
f - archive to file
x - Extract files  from tape (if files  not specified, extract all files)

Example
To backup 'abcd' dir, create an archive file 'abcd.tar' :
$ tar -cvf abcd.tar abcd

Note : c - create, v - verbose mode, f - archive to file.

To extract it back from the archive file:
$ tar -xvf abcd.tar

Note : The archive file can have any or no extension.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...