Vous êtes sur la page 1sur 20

UNIX

Naveen Kumar Srinivas Page 1



Unix Commands
1. date
Date is a valid UNIX command that
instructs the machine to display current
system date and time. The above
command does not prompt you to
change either the date and time as in
MS-DOS. System date and time can be
changed only by the system
administrator.

Example:
$date
o/p:
To change date format:
$ date +%m -
displays only the month
o/p:
$ date +%d -
displays only the date
o/p:
$ date +%y -
displays only the year
o/p:
$ date +%H -
displays the hour
o/p:
$ date +%M -
displays the minute
o/p:
$ date +%S -
displays the seconds
o/p:
$ date +TODAYS DATE
IS:%d-%m-%y
o/p:

2. banner
Produces a blown-up version i.e., in
large letters format of the characters that
is supplied with the command.
By default banner displays 10
characters per line.
Example:
$banner UNIX

3. cal
cal command is used to display the
calendar for any year in the range 1 to
9999.

Example:
$ cal
o/p:

the above command highlights the
current date as well as the displays
calendar of current month.

$ cal 5 2009
o/p :
The above command displays the
calendar for the 5
th
month of 2009.

4. who
This command displays an informative
listing of all users who are logged on to
the system. By default who command
produces a three column output.
Generally who command is used by
the system administrator to monitor the
user details.

Example:
$ who
o/p:

The first column shows the user login
names. The second column shows the
terminal information the user is using.
The next column shows the date and
time the user has logged into the
system.

Options used in who command:
1) -H option displays header
(title) information as shown below.
$ who H
o/p:

2) - u option is used to
display users information
along with PID, idle time
and other details
$ who u
o/p:

UNIX

Naveen Kumar Srinivas Page 2

5. who am i
This command is a special case of who
command where am and i are the
arguments.
It displays a single line of output
providing login details pertaining to the
user who invokes the command.

Example:
$who am i
o/p:

6. tty
UNIX operating system treats terminals
as files. tty ( teletype) command tells the
filename of the terminal the user is
using. All information about the devices
are present in the /dev directory. i.e., tty
gives the terminal information.

$tty
o/p:

7. passwd
This command is used to change the
password of the current user.
Example:
$passwd
o/p:
Passwd: changing password
for kumar
Enter login password: ********* ( existing password )
New password:********
Re-enter new password:
********
Passwd (SYSTEM):passwd
successfully changed for kumar
$

Passwd command asks for three times
the password. First it prompts for the
existing password. If valid password is
entered it prompts for the new
password. Finally it asks you to reenter
the new password.
passwd command when invoked will
ask for old password and then it
demands the new password twice. After
successful change the $ prompt is
displayed back.

8. echo
Echo command displays its arguments
produced along with the command. i.e.,
it outputs its string of characters it finds
on its command line.

Example:
$echo
o/p:
Prints a blank line
$ echo wel come to unix lab
o/p:

9.pwd
At any time you can determine where
you are in the file system hierarchy with
the pwd command, ( print working
directory or present working directory ).

Example:
$ pwd
o/p: /usr/usr1
the current working directory or the path
is displayed as /usr/usr1. / indicates
the root directory of the unix file system.
In this root directory there is a
subdirectory usr within which is another
subdirectory usr1. Forward slash ( / )
acts as a delimiter to file and directory
names except the first slash which is a
root.

10. bc
The calculator bc or base conversion is
invoked by typing bc command at the $
prompt, once typed bc you are in
calculator mode and $ is disappeared.

Example:
$ bc
10 +2
12 ( output)
2.5 * 100
250
12 * 12 ; 2 ^4 ( ^represents
power )
144
16
ctrl +d or quit to come out
UNIX

Naveen Kumar Srinivas Page 3


$bc
for (i=0;i<5;i++)i
0
1
2
3
4
quit

$bc
9/5
1

$bc
scale=2 ( used to truncate to 2
decimal places )
9/5
1.8

11. expr
Another method of calculation at the
command prompt is using expr
command.

Example:
$ expr 10 + 20
30
$ expr 20 \* 2 ( \* used for
mul tiplication )
40

12. factor
This command prints the prime factors
of the number supplied along with the
command.

Example:
$ factor
100
o/p:
( type q to quit )

12. Spell
UNIX was originally used for preparation
of documents. It has one important
feature known as spell checking.
Spell command is found in most of
the UNIX systems and takes the file
name as its arguments. It then
generates a list of spellings that the
program recognizes as mistakes.
$ spell students.list
o/p:
by default the spellings are checked with
reference to US dictionary, but using
b option spell command can be
changed to British dictionary.
$ spell b students.list
o/p:

( IN LINUX ispell command i s used
)

13. mkdi r
This command is used to create a
directory. Using this command we can
create any number of directories of sub-
directories in a single command. To
create directories the command should
be followed with name of the directory to
be created.

Example:
$ mkdir PROBETA
o/p
( the above command creates a
directory named PROBETA )

$ mkdir PROBETA1 bca unix
o/p
( this command create 3 directory in a
single command named PROBETA1,
bca and unix )

$ mkdir p
PROBETA111/bca/uni x/batch1
o/p
( The above command with p option
creates first PROBETA111 directory and
within this directory it creates bca and
within this it creates another directory
unix and then batch1.)

$ mkdir bca bca/unix bca/sp
bca/sad bca/dcn
o/p:
( This creates one directory bca and 4
subdirectories unix, sp, sad, dcn under
bca directory. The order of specifying
UNIX

Naveen Kumar Srinivas Page 4

this argument is important. The
subdirectory cannot be created before
creation of the parent directory. So the
parent directory has to be created first )

$ mkdir m 750 dir1
o/p

$ mkdir test
some times a directory cannot be
created due to three reasons.
1. The directory may already exist
2. There may be a ordinary file by that
name in the current directory
3. The user is not having adequate
authorization.

14. rmdir
This command is used to remove a
directory. rmdir removes only empty
directories. i.e., there should be no files
or any subdirectories in the directory to
be removed. i.e., there are two rules to
be followed while removing a directory.
1. A directory cannot be deleted
unless it is empty.
2. you cant remove a directory
unless you are placed in a
directory which is hierarchically
above the one you have chosen
to remove.

Example:
$ rmdir PROBETA
o/p
( removes PROBETA directory )

$rmdir bca/unix bca/sp
bca/sad bca/dcn bca
o/p:
( The above command deletes more
than one directory in a single instruction.
Care should be taken such that while
removing, directory should be removed
in the reverse direction of creation)

$ rmdir p
PROBETA111/bca/uni x/batch1
o/p:
( This command is used to delete
several subdirectories in a single
command)


15. cd
This command can be used to change
di rectory (cd) from the current directory
to the specified directory. The specified
directory should be present or else unix
reports an error.
After using cd tthen use pwd to see
which directory you are in.
cd without any arguments can be used
to go back to your home directory.
cd . . is used to goback one level back

Example:

$ cd english
o/p:
( Directory English should be
created or present.)

$ pwd
o/p:

$ cd ..
o/p:

$pwd
o/p:
16. cat
It is one of the most well-known
commands of the UNIX system. It can
be used for three purposes.
This command is used to create a new
file, view contents of existing file,
append a existing file and concatenate
two or more files.

1. To create a fil e: The syntax to
create a file is cat command, followed by
>(right chevron) and then the file name.
The symbol >tells the computer that
what is typed is to be put into the file.

Example:
UNIX

Naveen Kumar Srinivas Page 5

$ cat > colors
red
green
blue
< control- d >
$
<control- d >is used to save and exit.
Ctrl +d indicates the end of the file or
the end of the input to the system. Thus
when ctrl +d is pressed the cat
command understands that no further
input will be made. The data is saved to
the file name and the shell prompt $ is
seen at the command line.

2. To vi ew the contents of a file: To
display the contents of the file the syntax
used is, cat command followed by the
name of the file.
Example:
$ cat colors
o/p: red
green
blue

3. To concatenate two or more files:
cat command is also used to
concatenate the contents of two or more
files and store them in the third file. The
syntax is,
$ cat colors colors1
colors3 > newcolors
o/p:

The above command will add the
contents of three files colors1 colors2
colors3 to another file named
newcolors. If file newcolors does not
exist it will be created and if the file
newcolors exists the contents in the
file will be overwritten.


In the above the contents of the third file
newcolors was overwritten while
concatenating. Suppose the contents of
the third file should remain as it is then
we should use the output redirection
operator >> as shown below

$ cat >> colors
white
black
<control-d>

$ cat colors colors1
colors3 >> newcolors

17. cp

The cp (copy) command copies a file or
a group of files. It creates an exact
image of the file on the disk with a
different name.
The syntax of cp command requires
at least two filenames to be specified as
arguments to the command. Out of
these two files the first file should be
existing.

Example:
$ cp srcfile destfile
o/p:
This will copy the contents of srcfile into
a destnfile. if destnfile does not exist it
will be created. If the file exists Unix OS
overwrites the existing file without
warning.

Copying files to a di rectory.
$ cp file1 file2 file3 file4 di r1
o/p:
the above command copies all the files
to directory named dir1, provided that
the directory dir1 exist.

$ cp /usr/unix1/bca1/chap1
/usr/unix1/bca2/chapter1
o/p:
the above command copies the file
chap1 from the directory /usr/unix1/bca1
to the directory /usr/unix1/bca2. the file
name has been changed from chap to
chapter1.

$ cp
/usr/PROBETA/bca/chap1 .profil e
$ cp
/usr/PROBETA/bca/chap1 .
UNIX

Naveen Kumar Srinivas Page 6

. (dot) represents current directory. The
above command copies the file chap1
from /usr/PROBETA/bca to your current
directory.

$ cp chap* di r1
o/p:
The above command copies all files
beginning with chap1 to directory dir1.

Options used in cp command:
- i - is used for interacti ve
purpose. It prompts for confirmation
before overwriting the destination file, if
it already exists.
$ cp i file1 fil e2
o/p:
( if file2 exists, cp command prompts for
a response as below,
cp:overwrite file2 ?
a y at this prompts overwrites the file,
any other response leaves it uncopied )

- r - recursive copying.
This is used while copying the entire
directories. It copies all the files and
subdirectories recursively present in that
directory.
$ cp r dir1 dir2
o/p:
( the above command copies al l files
and subdirectories from dir1 to dir2 )

-p - perseveres the
permissions present for the file while
copying.

18. rm
rm command is used to remove files
from your directory. It is similar to del
command in MS-DOS.

Example:
$ rm letter
o/p:

$ rm letter1 letter2 letter3
o/p:
( thi s removes more than one file in a
single instruction )

Options in rm command:

$ rm letter *
o/p:
( Thi s is similar to the above
command. It removes all the files
beginning with letter)

$ rm -i letter4
o/p:

$ rm i fi le1 fil e2 file3
o/p:
Here -i is a switch(option) available in
unix which removed files interactively
i.e., you are asked for confirmation
before deleting the file. a y at this
prompts removes the file, any other
response leaves it as it is )

$ rm -f letter5
o/p:

This command with f option removes
files forcibl y, irrespective of whether
you have permission to that file or not.

rm command can also be used to
remove directori es using r
(recuricve) option.
$ rm r dir1
o/p

This command recursively (-r) removes
all contents of dir1 and also the directory
dir1.


19. mv renaming fil es
mv command is used to rename or
move files. Thus this command can be
used to rename file or move files from
one directory to another directory. This
command does not creates a copy of
the file it just moves or renames the file.
This command can be also used to
rename a directory.

Example:
UNIX

Naveen Kumar Srinivas Page 7

$ mv test testnew
o/p
( here test is renamed as testnew. This
is nothing but source file is erased from
its original location and copies at the
specified destination )

$ mv olddir newdir
o/p
( this command changes the name of
directory olddir to newdir )

$ mv file1 file2 file3 newdir
o/p

This command moves the three files
file1 file2 file3 to directory newdir. The
files will be removed from the original
location and are moved to newdir.

20. fil e
This command gives information on
what each file contains i.e., determines
the type of file the directory contains,
especially of an ordinary file. It displays
whether a ordinary file contains a plain
text, a exe file, a command file, a ASCII
file or even a empty file.
Example:
$ fil e *
o/p:

$file emp.list
o/p:
21. wc
wc command is a simple and useful
command which is used to count the
number of lines, number of words and
number of characters including the
space in a file.

Example:
$ wc fil e1
o/p 8 45 65 file1
in the above output it shows file1
contains 8 lines, 45 word and 65
characters.

$ wc fil e1 fi le2 fil e3
o/p

Options used in wc command:
$ wc l fi le1
o/p

$ wc w fil e1
o/p

$ wc c file1
o/p

22. ls
This command is similar to DIR
command as in DOS. It is used for
directory listing or list the contents of the
current directory or specified directory.

Example:
$ ls
o/p
here in the above output is displayed in
the sequence of file names beginning
with numbers first then file names
beginning with uppercase and then file
names beginning with lowercase. It also
lists directories.

Options used in ls command:

$ ls c*
o/p
this displays all file names starting with
character c where * is a metacharacter
indicating all.

$ ls /mydi r/c*
o/p
this displays all file names starting with
character c in the directory mydir,

$ ls [aeiou]*
o/p
this command indicates to display the
directory contents that contains the first
character in the file name to be any of
the letters given within the square
brackets. The remaining characters of
the file name can be anything.
Square is a meta-character whi ch is
used to specify range of values.
UNIX

Naveen Kumar Srinivas Page 8


$ ls [ ! aei ou ]*
o/p
the above command display all files that
does not begins with any of the letters
given within the square.

$ ls [a-m][c-z][0-9]??
o/p

this command lists all 5 character file
names in the current directory where
first character in the file name should be
in the range a to m, second character
top be in the range c to z and third
character to be in the range 0 to 9. the
fourth and fifth character can be any
thing.
? i s a metacharacter indicating onl y
one character

$ ls a
Show all files including hidden files. (
hidden files in unix begins with a . )

$ ls l
o/p

This command is used to display
directory contents in long list format.
In the above output the total indicates
the number of blocks that the files in the
current directory occupy. Generally a
single block is of 1024 bytes or will be in
the multiples of 512.
The next line consists of 9 columns. A
small hyphen () indicates it is a file, if it
is denoted by a d it indicates a directory.
The next nine characters following the
file type is the permissions given to the
files or the directory. The first three
characters is the permission given to
user or the owner, the next three is for
the group to which the user belongs and
the next three is for others.
The next column specifies the number of
links each file is having. The next
column specifies the owner name, group
name, size of the file in bytes, date and
time when the file was last modified and
finally the file name or the directory
name.

$ ls x
o/p
-x option along with the command
displays the directory contents in
multiple column format.
$ ls F
o/p:
-F option displays the executable files
and directories present in the current
directory.
* indicates that the file is a exe file and
a / indicates a directory.

$ ls r
o/p:
-r option displays the directory contents
in reverse order.

$ ls R
o/p:
-R option recursi vel y displays all the
files and sub-directories in a directory
tree.

[ Try -d, -t, -u , -i options ] ]

23. ln
This command is used create a link for a
file.
When a file has two links it is not
physically present on two locations, but
it can be referred by any of the two
names. This will be useful if you
accidentally delete a file with a single
link or a single name then you cannot
get back, but if a file has 2 links then if
you delete one of the file then you can
get back with the help of another link of
the same file. By default any file created
will have one link and any directory
created will have two links ( one the
current directory denoted by a . and
another root directory denoted by a ..)
When you create a link to a file both the
file will have the same inode number.
When a file is copied, both the original
file and copied file occupies space in the
UNIX

Naveen Kumar Srinivas Page 9

disk. When a link is created to a file a
single copy can b maintained in the disk
with two links and changes to one file
can be reflected in the other.
Example:
$ ln emp1 empbac
o/p:

the above command creates one more
link for the file emp1 in the form of the
name empbac.

24. touch

The touch command can be used to
create a new (empty) file or to update
the last access and modification
date/time on an existing file.

Options used in touch command:
-a change the access time of the file
-m change the modification time of the
file
-t time use the time specified, not the
current time
When setting the "-t time" option it
should be in the form:
[[CC]YY]MMDDhhmm[.SS]
where:
CC first two digits of the year
YY second two digits of the year
MM month, 01-12
DD day of month, 01-31
hh hour of day, 00-23
mm minute, 00-59
SS second, 00-60
The date_time has the form:
MMDDhhmm[YY]
where these have the same meanings
as above.
The date cannot be set to be before
1969 or after J anuary 18, 2038.

Examples:
$ touch 03161430 empname
$ touch m 02281030
empname
$ touch a 02281030 empname
$ touch f1 f2 f3 f4 f5
(creates 5 empty fil es with zero bytes
)
$ touch file1
( i f fi le1 is exi sting then modification
as wel l as access time i s set to
current date and time )

25. sort
This command can be used for sorting
the contents of a file in alphabetical
order line by line.
Sort command first compares the first
character in each line in a file. If the first
character in the two lines is same then
the second character in each line is
compared and so on. Sorting is done
according to ASCII format. i.e., first
sorts the spaces, then tabs and then
punctuation marks followed by numbers,
upper case letter and lower case letters.

Example:
$ sort file1
o/p

$ sort file2 fil e3 file4
o/p

Options used in sort command:
$ sort o result file1 fil e2
fil e3
o/p
the above command sorts the three files
file1, file2,file3 and the result is stored in
result.

Try - r, - n , - nr

26. df
df can be used to see how much of the
disk is being used and what part of it lies
free. Thus df command can be used to
report the free space as well as the used
disk space on your machine.

Example:
$df
o/p:
The first column shows the directory to
which the file is attached. The second
UNIX

Naveen Kumar Srinivas Page 10

column shows the name of the file
system. The third column shows the
number of blocks available. The last
column shows the number of free i-
nodes available.

27. du disk usage
du command reports the disk usage of
each files and directories in the current
directory. It reports the usage in terms of
blocks.
Example:
$du
o/p:
options used in du command:

$ du s
o/p:
( it reports onl y the total sum)

$ du k
o/p:
( reports the fi le si zes in units of 1024
bytes )

28. ul imit
ulimit stands for user limi t. It is used for
setting limits on file sizes. It contains a
value which signifies the largest file that
can be created by the user in the file
system.
$ ulimit 1024
This implies that the user cannot create
a file whose size is bigger than 1024
bytes.
The changes to the user file limit will be
restricted only to the current session and
the system will return to its default value
when logged out.
An ordinary user can only reduce the
ulimit value and is never permitted to
increase it. A super user can increase or
decrease the ulimit value of a file.

29. cut
Cut command is filter command. It cuts
or picks up for displaying the given
number of characters or fields from
each line from a specified file .
For example if you have a file which
contains employee details and want to
retrieve only employees sal and dept.
details from the entire file then cut
command can be used. When using this
command no changes will be made to
the source file.

Example:
$ cut c 2- 5 fi le10
o/p:
This will remove columns (character)
from 2 to 5 in the file10.

$ cut c 1, 5,10 fil e10
o/p:
This will remove 1, 5, 10 columns
(character) from the file10

$ cut c 6-10, 36-40 fil e10
o/p:

$ cut c 10 fi le1
o/p:
This will remove starting from the 10
th

column from file1.

$ cut f 2,7 file1
o/p
This will cut from field 2
nd
and 7
th
from
file1 and display.

$ cut f 2-7 file1
o/p
This will cut from field 2
nd
to 7
th
from
file1 and display.

By default fields will be separated by
either space or tab, but if fields is
separated by other characters like : or ;
then we have to use d (delimiter)
option to specify the field separator. ( d
is used to speci fy a si ngle character
onl y )
$ cut f 2,7 fi le1 -d ;
o/p
the above removes the 2
nd
and 7
th
field
from file1 and here the filed separator is
assumed to be ; .
UNIX

Naveen Kumar Srinivas Page 11

For example the file empdetails contains
the following fields in the following
format.
Empno%EmpName%EmpDep
%EmpSal%EmpAge%
104%AAA%sales%15000%40
105%BBB%mktg%10000%45
106%CCC%admin%9000%54
here each field is separated by a %. So
this is specified in the d option as
shown below,
$ cut f 2,4 empdetails d
%
o/p:

$ cut f 2- 4 empdetails d
%
o/p:

30. paste
It is a filter command which is used for
concatenation. It pastes the contents
vertically. At least two files should be
specified for this command as
arguments.
The contents of the original file will not
be changed and the output obtained can
be redirected to another file.

Example:
$ paste fil e1 fi le2
o/p:

By default paste command uses tab
character for pasting files. d ( delimiter)
option can be used to specify your own
delimiter to separate the contents of
both the files. ( d is used to specify a
single character onl y )
$ paste d X file1 fil e2
o/p:

$ paste d X file1 fil e2 >fil e3
o/p:

31. grep grep is nothing but globally
search for a regular expression and
print it.
This command would search the word or
the variable in the named file and prints
each line that contains an instance of
the pattern. While forming the patterns
to be searched we can also use meta-
characters. Like *, ?, [ ].

Syntax:
$ grep option pattern
fil ename

Example:
$grep picture file123
o/p
The above command would search for
the word picture in the file file123 and if
found prints on the screen the lines
containing it.

$grep hello file111 file222
fil e333 file444
o/p
The above command would search for
the word hello in more than one file
and if found would display along with the
name of the file where it occurred.

Options used in grep command:

$grep hello i file111
fil e222
o/p
-i is case insensitive

For a search involving more than one
word, single quotes should be used as
shown below.
$ grep my name is I file1
fil e2
o/p:

$ grep c sales emp1 emp2
o/p:
-c (count) option counts the occurrences
of a pattern. i.e., the number of times the
pattern appears in that file.

$ grep n sales emp1 emp2
o/p:
-n (number) option is used to display the
line numbers containing the pattern

UNIX

Naveen Kumar Srinivas Page 12

$ grep [Rr]ain file1
o/p:

$ grep b??k file122
o/p:

$grep v a
x
myfi le
o/p:
This command displays all lines that do
not contain words starting with a

32.chmod
This command is used to change the
permissions of a file or directory. This
can be done by the owner of the file or
the super user.
The syntax of chmod is,
$ chmod [who] [+/-/=]
[permi ssions] file
Here who refers to whom the
permissions is to be granted. It may be
the user(u), group (g) or the others(o). if
none is specified it is assumed all.
+ refers to grant or add
permissions
- refers to remove permissions
= refers to add specified
permission and remove other existing
permission.

The permission signifies who all can
access the file or the directory and for
what purpose. A set of nine characters
denote these permissions for three type
of users.
There are three type of permissions,
r read
w write
x execute

similarly there are three type of uses,
user or the owner u
group g
others o

Of the nine characters, the first three
characters decides the permission held
by the owner of the file, the next three
character specify the permissions for the
group to which the user belongs and the
last three characters specify to the other
user outside the group.
The permissions can be also encoded
numerically also known as octal
representation. Here the three
permission has assigned a numerical
values like,
read permission - 4
write permission - 2
execute permission - 1
thus when all three permissions is
assigned , the total value will be equal to
7, or if a file is assigned a permission of
6 it indicate read and write permission, if
it is 5 it indicates a read and execute
permission.
Thus 777 indicates all permission for all
type of users where as 000 indicates no
permission for all the users.
After each changes the permi ssion
can be checked using ls l command.
Example:
$ chmod 777 file1
o/p
$ ls -l

$ chmod 451 file2
o/p
$ ls -l

$ chmod 350 file3
o/p
$ ls -l

This method of numerical representation
is referred as Absolute mode or octal
mode.
There is another method known as
symboli c mode or relative mode
which uses +or or =to change the file
permissions.

Example:
$ chmod +w file1
o/p
$ ls -l

$ chmod go-x fi le2
o/p
$ ls -l
UNIX

Naveen Kumar Srinivas Page 13


$ chmod go+r,go-w file3
o/p
$ ls -l

$ chmod go=r,u=rw file4
o/p:
$ ls -l

33. head
Using cat command we can view the
contents of a file. However if the file is
bigger than 24 lines then the file
contents would scroll to the next page.
Thus if we want to have a control over
viewing the contents of a file according
to our requirement we can use head or
tail command.
Head command is used view the file
contents at the beginning of the file.
By default head displays first 10 lines in
the file.

Example:
$head fi le1
o/p

$head -16 fil e3
o/p
This is used to view the first 16 lines of
file3.

34. tail
Head command is used view the file
contents at the beginning of the file.
Where as tail command is used to view
the file contents from the end of the file.
By default tail displays last 10 lines in
the file.

Example:
$ tail file1
o/p

$ tail -14 file3
o/p:
This is used to view the last 14 lines of
file3.


34. pg
This is a filter command which is used to
view the contents of a page based on
specifying the page numbers.
In head and tail command we can
view the contents starting from the
beginning and from the end, but if we
want to view a specific page then we us
pg command.

Example:
$ pg +10 -3 file1
o/p:
The above command starts displaying
the contents of the file1 starting from the
10
th
page and 3 lines at a time.

$ pg +10 -3 -p fil e1
o/p:
-p option is used to Print the page
number at the end of each page.

35. more
If the contents of file exceed more than
24 line it cannot be seen using cat
command, it scrolls down. Using head
and tail command we can view the
contents starting from the page
beginning and from the end. So to view
a specific page contents we use pg or
more command.
more command allows the user to view
a file contents one screen at a time and
according to users request of the page
numbers.
Example:
$ more chap01
o/p:
When the above command is entered
we can see the contents of chap01 file
on the screen one page at a time. At the
bottom of the screen, you will also see
the file name and the percentage of the
file that has been viewed.
:
chap01 (55 %)
$ more +10 -5 file1
o/p:
UNIX

Naveen Kumar Srinivas Page 14

The above command starts displaying
the contents of the file1 starting from the
10
th
page and 5 lines at a time.

Multiple file contents can also be viewed
using the same command as shown
below,
$ more +10 -5 file1 file2 file3
o/p:
when multiple filenames are given, all
the files are displayed one by one, page
by page starting from the first file.
To come out or quit from more
screen the user has to press q.
To scroll forward one screen f key
has to be pressed. Similarly to scroll
backwards b can be used.

36. ps
[ Process is nothing but program under
execution. A process is born the
moment it starts executing and is dead
once it terminates. For a process to be
born another process should give birth
to it. The new process is known as the
child process and the process that starts
it is called the parent process. The child
born out of a parent can become a
parent by giving birth to another child
process. PPID is nothing but the
process id of the parent. ]

ps command displays the processes
that are running at any instant of
time.

Example:
$ ps
O/p:
PID TTY TIME
COMMAND
2269 3a 0.05 sh
2396 3b 0.15 ps
Unix assigns a unique id to every
process running in memory. This
number is called process ID or simply
PID.
The PIDs start with 0 and runs upto a
maximum of 32767. When the maximum
number is reached it starts counting
allover from 0.
The output of above ps command
shows the PID of two processes being
run by the user when ps was
executed. The output also shows the
terminal information from which the
processes were launched, the time that
has elapsed since the processes were
launched and the names of the
processes.

Options used in ps command:

1. To display process of all users.
$ ps a
o/p:

2. To displ ay the process of a
parti cular user.
$ ps u user1
o/p:
( user1 is the login name of the user
for which the process information
is to be retrieved )

3. To displ ays full listing of all
process including the PPID.
$ ps f
o/p:
UID PID PPID C STIME
TTY TIME
COMMAND
PROBETA1 2520 522 0
16.30 3a 00.00.15
-sh

A process is born the moment it starts
executing and is dead once it
terminates. For a process to be born
another process should give birth to it. In
UNIX the new process born is called the
child process where as the process
that starts it is called the parent
process.
In the above output,
UID - It is the name of
the user.
PID - It is the unique
process-id for each command.
UNIX

Naveen Kumar Srinivas Page 15

PPID - is nothing but the
Process-ID of the Parent.
C - CPU time
consumed
STIME - Starting time of the
process
TTY - Terminal
information
TIME - Total time elapsed
after the start of the process

4. To displays process under execution
like system process.
$ ps e
o/p:

5. To display process executed from a
particular terminal
$ ps t tty3a
o/p:

To kill a process the command used
is kill
$ kill 6173
o/p:
where 6173 is the process-id of the
process to be killed.
Multiple process can be killed as shown
below,
$ kill 6173 6758 9526 5864
o/p:

To kill all process excluding the login
shell, a special argument 0 has to be
used.
$ kill 0
o/p:

A process can be killed using a number
9, known as sure kill signal which is
nothing but kill by force.
$ kill - 9 2316
o/p:
After killing (terminating) the process
existence can be checked using ps
command.


37. uniq
This command is used to remove
duplicate or repeated lines found in a
file.
Example:
$ cat >dept.l ist
sal es
marketing
admin
accts
sal es
marketing
accts
admin
< CTRL + d >
If uniq command is used to the above
file then it will delete all the repeated
lines present in the file and displays
non-repeated lines.

$ uniq dept.list
o/p:

-c option can be used to count the
number of times the line occurred in the
file.

$ uniq c dept.list
o/p:

38.cmp
This command compares two files byte
by byte that is character by character,
and then the location of the fi rst
mismatch is displayed on the screen.
No next mismatches are displayed.
It requires at least two files as
arguments for comparing.
Example:
$ cmp fi le1 fil e2
o/p: fil e1 fi le 2 di ffer: char9, l ine1

In the above output in the ninth
character of the first line a mismatch
was found.
If both the files are identical , no
message is displayed.

-l option can be used to display
subsequent mismatches in both the
files.
UNIX

Naveen Kumar Srinivas Page 16

$ cmp l file1 file2
o/p:

39. logname
Displays the login name of the user.
$ logname
o/p:

40. uname
Displays the information of the unix
system
$ uname
o/p:

$ uname X
o/p:
displays the release version number,
type of microprocessor used and other
information related to UNIX system.

41. lp
UNIX OS permits sharing of one printer
amongst all users. When several users
makes a request to print their requests
are put on a queue and then printed
according to the precedence. A print
schedule runs in the background which
manages the print jobs of different
users.

The lp command is used to send the
users print job to the print queue. It is a
line printing command. When we submit
the job for printing using the lp
command it returns a request id. This
id can be used to keep track of our print
jobs or to cancel any print jobs. When a
lp command is used it adds a banner
page or title at the beginning of our
printout which helps in identifying his
printout from the heap of printouts that
are printed by different users.

Example:

$ lp fi le1
o/p: request id is lp-32

Multiple fil es can be printed in a
single command as shown below,
$ lp fi le1 file2
o/p: request id i s lp-325 (2 fi les)

-o option can be used to disable the
banner or title that is printed on each
pages of print.
$ lp o nobanner fil e1
o/p:request id is lp-3268


To get information or message when our
print job has been completed we
can use m option

$lp m file1
o/p : request id is lp-325

now when the printing is over we would
be informed by a message on our
screen. If we have logged of the
message would be mailed.

If we want multiple copies to be printed
then we can use n option where
n is the number of copies required.
Default is 1.

$lp n 25 fil e1
o/p: request id i s lp-3248

If we want to specify a printer other than
a default printer then we can use
d option which is used to specify the
printer name.

$ lp d hp3500 file1
o/p: request id i s hp-3285


-t option can be used to print our own
title instead of the default title or banner.
$ lp t IV SEM BCA fil e1 file2
o/p: request id i s lp-3696


-P option can be used to specify the
page number to be printed.
$ lp P 10 fi le1
o/p: request id i s lp-32586
Prints the 10
th
page from file1.
UNIX

Naveen Kumar Srinivas Page 17



42. lpstat
This command is used to see the status
or progress of our print request.

Example:
$ lpstat
o/p:

$ lpstat t
The above command gives the status of
print jobs and also it gives other
information like type of printer, whether it
is accepting any new print requests.

To cancel the print jobs we have
submitted we can use the cancel
command along with the request-id of
the respective file to be cancelled.

$ cancel lp-14
o/p:
where lp-14 is the request id of our print
job. We get a message on our screen
request lp-14 cancelled. We can
cancel only our print job which we have
submitted where as super user can
cancel all the users print job.

43. lpr
Linux using Berkley Software
Division(BSD) system the command to
print files is lpr. This command does not
display any job number when executed.

Example:
$ lpr fi le1
o/p:

$ lpr P hp500 fil e1
-P (CAPITAL) is used to specify the type
of printer

$ lpr T Welcome fil e1 file2
-T is used to print titles on the file to be
printed. Here it prints Welcome on
the paper.

$ lpr -#25 file1
#option is used top specify the number
of copies required.

$ lpr m file1 file2
-m sends a message to our screen
when the print job is completed.

44. lpq
This command shows the print queues
or the status of all the print jobs that has
been issued. ( similar to lpstat command
used in system V based linux system )

Example:
$ lpq
o/p:

45. lprm
The above command is used to remove
or cancel print jobs from the print
queue. We can only remove our print
jobs which we have issued.

Example:
$ lprm 31
o/p: Removes job numbered 13

$ lprm
o/p: removes all jobs owned by the
user.

46. tput
This command is used to control the
way output is displayed on the screen.
For example we want to clear the
screen, or we want to display the text in
bold letters, or blink the character. To do
all this we can use the tput command.
tput command should be used with any
arguments.

$ tput cl ear
$ tput bold
$ tput lines
$tput blink
$ tput cup 10 20


47. compress
UNIX

Naveen Kumar Srinivas Page 18

This command can be used to
compressed to a fraction of its orginal
size. Compress command can be used
to save disk space. For example to
compress a file called trial.txt the
command is,

Example
$ compress trial.txt
when this command is executed a .Z
extension file is added to the orginal file
which tells the file is a compressed file.
Compression is dependent on the
contents of the file, sometimes it may
not be possible to compress all files in
such cases the compress command
informs us and doesnt create a .Z file.

$ compress v trial.txt
o/p: trial.txt : Compression: 43.25
% - replaced with trial.txt.Z
This command with v option tells how
much space it saved by compressing
the file.

To get the compressed file to the
original state, we can use the
uncompress command.

$ uncompress trial.txt.Z
o/p:
on doing this the compressed file
trial.txt.Z file is deleted and the orginal
file trial.txt is recreated back.

The compressed file cannot be viewed
using the cat command. To view the
compressed file the command is,

$ zcat trial.txt.Z
o/p:

48. pack
pack command is similar to compress
command but uses a different
method. It is also used to compress
the file thereby reducing the file
space.
Example:
$ pack trial.txt
o/p: 37.50 % compression
from the above we can see that the
degree of compression is lesser
compared to compress command. Also
compress is faster compared to pack
command.
After compression a file with .Z
extension is created and the original file
is deleted. In the above trial.txt is
deleted and a compressed file trial.txt.Z
is created.
To view the contents of file compressed
using pack command, pcat command
has to be used.
$ pcat tri al.txt.Z

to get back the orginal file unpack
command is used as shown below.
$ unpack trial.txt.Z
Now the packed file is deleted and the
original file is restored.

49. gzip
compress and pack command is used in
UNIX operating system to compress a
file.
gzip is used in LINUX operating system
to compress a file. gzip creates a file
with a .gz extension and deletes the
original file.

Example:
$ gzip file1
o/p:
Produces a file1.gz file

- v option can be used to display how
many compression is achieved in terms
of percentage.
$ gzip v fil e1
o/p:

- r option can be used to compress
recursively. A directory has to be
specified while using r option

50. gunzip
To uncompress a compessed file with
.gz extension, gunzip is used as shown
below,
UNIX

Naveen Kumar Srinivas Page 19

Example:
$ gunzip file1.gz
o/p:
now file1.gz is deleted and the original
file is restored.


51. zip
zip is another command used in LINUX
to compress a file. Here a zip extension
is created for the zipped file.

Example:
$ zip fil e1 *.doc
o/p:
It compresses all .doc files and
produces file1.zip.
unzip i s used to decompress a .zip
file
$ unzip fil e1 .zip
o/p:


52. at
53. batch
54. crontab
55. nohup
56. ni ce

57. mail
Using this command we can quickly and
efficiently circulate memos and
other written information to several
users.
To send a mail, use the mail command
and then enter the usernames. We
can send the same mail to several users
at a time

$ mai l user2
subject: hi
dfhdjfhj
dfkdkfj dfhjdfh
<ctrl + d >

when we enter the above command we
get a prompt asking for the subject
and then after entering the subject
we can start entering our message.
To stop entering we have to press
ctrl +d.

to send mail to several users,

$ mai l user2 user3 user4
subject: hi
dfhdjfhj
dfkdkfj dfhjdfh
<ctrl + d >

we can also redirect a fil e to users.

$ mai l user2 user3 user4 < file.c
now the contents of file.c would be
mailed to all the three users user2,
user3, user4

To read the mail: If the user is logged in
the user would get a message on
the screen you have mail . Then
the user has to just enter mail at
the shell prompt.

$ mai l
o/p:

The output consists of all the details of
the mails received by the user. It
displays the number of new (N)
messages and also unread (U)
messages. It also displays a number
to each message, and then a & is
displayed at the bottom which
prompts us to enter the number of
the message to be read. Suppose
we want to read the 2
nd
mail then we
can enter 2 at the & prompt.
To come out of the mail command we
can type q at the & prompt to quit.

58. wall
This is another communication
command. This command can be
used to send message to any users.
The difference between the wall
command and other communication
commands like mail, write is,
1. Wall command can be used only
by the super user.
UNIX

Naveen Kumar Srinivas Page 20

2. it is used to broadcast messages
or send mails to all the users.

Wall command enables the super user
to write to all irrespective of whether
the users have given write permissions
or not.

$ wall
System shutting down in 10 minutes.
<ctrl + d >
all users who have logged in will hear a
beep and see a message flashed on
their screens.