Sei sulla pagina 1di 46

UNIT -1

1.1 Introduction:
A computer system cannot function without an
operating system. An operating system is a
collection of programs that co-ordinates the
operation of computer hardware and software. It
is a life giver to a computer. Technically speaking
it is a program that is loaded into the computers
memory when the system is booted, and it always
remains there. There are many different operating
systems available for Personal Computers, minicomputers and mainframes, the most
common ones being Windows NT and 2000, VMS and variations of UNIX. UNIX is
available for many different hardware platforms whereas most other Operating
Systems are tied to a specific hardware family.
What is UNIX?
UNIX is a powerful computer operating system originally developed at AT&T Bell
Laboratories in the 1960s. It is very popular among the scientific, engineering, and
academic communities due to its multi-user and multi-tasking environment, flexibility
and portability, electronic mail and networking capabilities, and the numerous
programming, text processing and scientific utilities available. It has also gained
widespread acceptance in government and business.
1.1.1 UNIX features:
1. Multi user capability: It allows many users to access a computer system at the
same time (multi user capability). It shares CPUs memory and disk space in a fair
and efficient manner among competing processes.
1. It supports the creation, modification and destruction of programs, processes and
files.
1. Hierarchy: It provides directory hierarchy that gives a location to processes and
files.
1. Multi tasking capability: it is capable of carrying out more than one job at the
same time.
1. o!!unication: Unix has excellent provision for communicating with fellow users.
The communication may be within the network of a single main computer, or
between two or more such computer networks. The users can easily exchange mail,
data, programs through such networks.
1. "ecurity: Unix allows sharing of data, but not indiscriminately. Unix has three
inherent provisions for protecting data.
The first is provided by assigning passwords and login names to individual
users ensuring that not anybody can come and have access.
At the file level, there are read, write and execute permissions to each file
which decide who can access a particular file, who can modify it and who can
execute it.
Lastly, there is file encryption. This utility encodes a file into an unreadable
format, so that even if someone succeeds in opening it, our secrets are safe.
1. #ortability: one of the main reasons for the universal popularity of Unix is that it
can be ported to almost any computer system.
2. It supports both Graphical User Interface (GUI) and Character User Interface (CUI).
3. It is ase "ensiti$e operating system. It treats lower-case characters differently
than upper-case characters. For example, the hles readme, Readme, and README
would be treated as three different hles.
4. A major feature of Unix is that much of it was written in and made it very popular as a
systems programming language.
1%1%& Uni' syste! (rchitecture)
The functioning of Unix is divided in three levels: on the outer crust reside the application
programs and other utilities, which speak over language. At the heart of Unix, on the other
hand, is the kernel, which interacts with the actual hardware in machine language. The
stream lining of these three modes of communication is done by the middle layer, called the
shell. The shell or the command interpreter as it is called, is the mediator which interprets
the commands that we give and then conveys them to the kernel which ultimately executes
them. The kernel has various functions. It manages files, carries out all the data transfer
between the file system and the hardware, and also manages memory.
The kernel program is usually stored in a file called `Unix whereas the shell program is in a
file called sh. At a particular point in time there may be several shells running in memory
but only one kernel. This is because, at any instance Unix is capable of executing only one
program as the other programs wait for their data. And since its the kernel which executes
the program one kernel is sufficient and since the user interacts with the kernel through the
shell different shells are necessary.
. . .

*ig) Uni' (rchitecture
1%& The UNIX *ile "yste!
The Unix file system resembles an upside down tree. Thus, the file system begins with a
directory called root. The root directory is denoted as slash (/). Branching from the root
there are several other directories called bin+ lib+ usr+ etc+ t!p and de$. The root
directory also contains a file called Unix which is Unix kernel itself. These directories are
called sub-directories, their parent being the root directory. Each of these sub-directories
called sub-sub-directories. The following figure shows the basic structure of the Unix file
system:
"T,UTU,- .* ( *I/- "0"T-M
1. The bin directory contains all executable files, for the most of the Unix commands
which the user can run.
2. The sbin directory contains unix commands which are required for Administrator.
The system contains there machine language files in sbin directory.
3. The proc directory contains system information as per process based. It well very
much useful to identify the regions for system crashes.
4. The lib directory contains all library functions, provided by the Unix programmers.
5. The de$ directory contains files that control various input/output devices like
terminals, printer, disk drivers etc.
6. In the usr directory there are several directories, each associated with a particular
user. Within the usr directory there is another bin directory, which contains
additional Unix command files.
7. The t!p directory contains the temporary files created by Unix or by the users.
8. The usr directory contains compilers, windowing softwares, games, debuggers,
manual pages, other documentation along with header files and language files.
a. The usr1local directory contains a site specific software (whenever we loaded
new software into system it is stored in local directory).
b. The usr1include directory contains the standard header files used by c
programs.
c. The usr1lib directory contains all library files in binary form. The user require
to link c programs with files in these directories.
9. The etc directory contains the configuration files of the system. Which are required
to the modify by the admin whenever he wants to add a new driver or partition or
win wide driver or has a user or enable a network card etc.,
10. The boot directory contains operating system files i.e kernel files.
11. The ho!e directory contains one directory for every legal user of the machine. For
users can create, remove, modify the files and directories in his home directory only
nowhere else they will be having freedom unless the users are ignorant about how to
protect themselves.
12. The $ar directory contains all print jobs and outgoing and incoming mails.
13. The !an directory contains the format and displays the on-line manual pages.
manpath - determine user's search path for man pages.
Following are the salient features of the Unix file system.
1. It has a hierarchical file structure
1. Files can grow dynamically
1. Files have access permissions
1. All devices are implemented as files
1%2 /INUX UTI/ITI-")
There are several hundred commands in UNIX. The Utilities are used to do specific task of
required by user. We can issue commands at $ prompt.
1 All Unix commands must always be entered in small case letters.
1 Between the command name and the options there must be always a space or a tab.
For example, ls l. Here ls is the command whereas l is the option and the two
have been separated by a space. The option is usually preceded by a minus (-) sign.
The options available with a command are often known as switches.
1 Two or more options available with a command can usually be combined. For
example, the command ls l a is same as ls la.
1 If you make a typing mistake, press backspace to erase characters. Dont try to
correct them using arrow keys and then deleting with the Del key.
1 To cancel the entire command before you press Enter, press the Del key.
Basic Commands:
1%2%1 reating *iles)
To create a file with a few lines in it, cat command is used.
"yn) 3cat options 4filena!e5
option
657 8 Creating file
647 Displaying content of given file.
6557 Appending to output redirection operator
686 Interactive input
6446 Here the document
-': $ cat > example
VCE is affiliated to JNTU HYDERABAD
It offers UG & PG courses
Then press ctrl9d :;hich is -.*<
To display the content of a file, $cat filename
-': $cat <example
Then the content of example file are displayed.
The cat command is also used to concatenate the contents of two files and store them in the
third file
-': $cat example1 example2 > new1
This would create `new1 which contains contents of `example1 followed by `example2. If
`new1 already contains something it would be overwritten.
If the contents of new1 should not change, then `append output redirection operator >> is
used.
-': $cat example1 example2 >> new1
1%2%& #resent Working =irectory)
To display current working directory of user, pwd command is used.
"yn) 3p;d
Displays current working directory of user
-' $ pwd
/usr/user1
Here the current working directory is displayed as /usr/user1. The / denotes the root
directory of the Unix file system. Within this root directory there is a sub- directory called
usr within which there is another directory called user1. Thats when we are working right
now. Hence the path from the root directory is listed as /usr/user1.
1%2%2 hange =irectory)
To change current working directory to new directory.
"yn) 3cd 4directoryna!e5
It change directory to new directory
-': $ cd ..
This will change directory to previous directory.
cd when given without any argument is interpreted by the shell as a request to change over
to the current user's home directory.
1%2%> /isting files and directories)
"yn) 3ls options 4directoryna!e514filena!e5
The ls command gives the directory listing or lists the contents of current or specified
directory.
-': $ ls
one
dw.c
it
svec
It lists all the files and sub directories of current working directory.
-': $ls -a
-a option is used to display the hidden files.
Here
. stands for current directory
.. stands for parent directory.
-': $ls p*
It displays all the files starting with character `p
-': $ls ?ain
This displays all the files ending with `ain, where the length of the file is 4 characters
(starting character may be any letter).
-': $ls [aeiou]*
This indicates that the first character of the filename to be listed must be any one of the
character given within the square brackets.
-': $ls [!aeiou]*
The `! symbol complements the condition that follows it. Hence the above command would
list all those files whose first character is anything other than a vowel.
The [ ] is always substituted by a single character.
-': $ls [a-m][c-z][4-9]??
This will list all 5 character filenames in the current directory whose first character is in the
range `a to `m, the second character is in the range `c to `z, the third character is in the
range
`4 to `9, whereas the fourth and fifth are any valid characters.
$ ls l
Total 22
`Total 22 indicates that the total number of disk blocks that the files in the current directory
have occupied is 22. unix treats all entities files directories, devices as files. Thus to
distinguish between all of them it uses file types. All the lines listed in the output of the
command ls l the left most character indicates this type. A `-` indicates the file is an
ordinary file, whereas a `d indicates that it is a directory. Other possible file types are given
bellow:
-': $ ls r
This lists all the files in the present directory including the files present in any sub-
directories that may be present in the current directory.
Two more options are useful with ls `-s and `-i. The `-s option lists the files along with their
sizes (in blocks, not bytes), whereas, the `-I option lists the files along with their inode
numbers.
lc: It displays the files in columns fashion
lf : It puts a * after all executable files and a / after all sub-directories present in the current
directory.
Thus, lf provides a handy way to determine which is an ordinary file, which is a directory
and which is an executable file.
*ile type Meaning
- ordinary file
d directory file
c character special file
b Block special file
l symbolic link
s semaphore
p named pipe
m shared memory file.
The character special files and the block special files are normally present in the /dev
directory. These files are used to handle character-oriented devices like terminals or block-
oriented devices like disks.
The next nine characters following the file type character are the file permissions. Each
column in succession gives the m=number of links, owner name, group name, size of file in
bytes, date and time when the file was last modified, and finally the file name.
-': $ln file1 filename1
This establishes one more links for the file, in the form of the name filename1.
The number of links to a file is determined by the number of different names through which
the file is accessible. When a file has two links, it is not physically present at two places,
but can be referred to by either of the names.
If one file is deleted, then another exists. The concept of having several links to a file offers
another advantage. If one file is to be shared between several users, instead of giving each
user a separate copy of the same file we can create links of this file in each users directory.
This avoids unnecessary duplication of the same file contents in different directories.
By default any new file that we create has one link whereas any new directory we create
has two links. Because that directory name appears in two directory files. For example, if
we create a directory `dir1 in a directory `d1, the directory file `d1 would have an entry
`dir1, whereas the directory file `dir1 itself would also have an entry `dir1 (which stands for
current directory).
1%2%? bc) best calculator
Once you type bc at the prompt, you are in the calculator mode, and the $prompt
disappears.
-': $bc
10/2*2
10
quit
-': $bc
scale=1
2.25+1
3.25
The variable scale is used to indicate the no.of digits after decimal point. Here, the actual
result is more than 3.3, (i.e 3.35) that's why scale has no effect.
-': $bc
ibase=2
obase=16
11010011
89275
1010
A
quit
By setting the variable ibase to 2 and obase to 16 all input that we supply is taken as a
binary number whereas all output is displayed in hexadecimal.
bc also supports functions like sqrt, cosine, sine, tangent etc.
$bc
sqrt(196)
14
$bc -l s() & c() are sine() and cosine() which are invoked only with -l option of bc.
scale=2
s(3.14)
0
1%2%@ To display the current date and ti!e+ there is the date co!!and%
$date
Fri may 16 08:25:53 IST 1997
1) $date '+Date:%d-%m-%y%n Time:%H:%M:%S'
Date:17-12-05
Time:10:55:35
=ifferent /inu' Utilities are)
1. *ile Handling Utilities) cp+ !$+ r!+ !kdir+ r!dir%
2. "ecurity by *ile #er!issions) ch!od+ chgrp+ cho;n+ u!ask%
3. =isk Utilities) du+ df+ uli!it+ find+ !ount+ u!ount%
4. #rocess Utilities) ps+ ;ho+ ;+ finger%
5. Te't #rocessing Utilities) head+ tail+ sort+ nl+ uniA+ grep+ egrep+ fgrep+ cut+
paste+ Boin+ !ore+ pg+ ;c+ tee+ co!!+ c!p+ diff+ tr+ ln+ a;k%
6. Cackup Utilities cpio+ tar%
7. Net;ork Utilities) ftp+ rlogin+ telnet+ arp%
1%> *ile Handling Utilities) cp, mv, rm, mkdir, rmdir.
1%>%1 cp :opying *iles<
The cp command copies a file or a group of files. It creates an exact image of the file on
disk with a different name.
"yn) 3cp options 4sourcefilena!e5 4destinationfilena!e5
.ptions)
-i Interactive copying
-R Copying Directory Structure
-': $cp t1 t2
This will copy the contents of t1 into t2. If t2 does not exist, it will be created. However, if
t2 already exists, then its contents are overwritten.
-': $cp t1 t2 three
Provided that the directory three exists, both files t1 and t2 would be copied to it.
-': $cp /usr/a1/chapter1 /usr/a1/n1/chap1
Here the file chapter1 is copied from the directory /usr/a1 to the directory /usr/a1/n1
instead of chapter1.
-': $cp -i t1 t2
cp: overwrite t2 (Yes/No)?
This will copy the contents of t1 into t2. If t2 does not exist, it will be created. However, if
t2 already exists, then it warns the user before overwritten contents to a file. If y at this
prompt overwrites the file, any other response leaves it uncopied.
-': $cp R progs newprogs
This will copies all files and sub directories in progs to newprogs directory recursively.
1%>%& r! :,e!o$ing files<
The rm command removes the given file or files supplied to it.
"yn) 3r! options 4filena!e:s<5
.ptions)
-i Interactive deletion
-r Recursive deletion
-F Forcing Removal
-': $rm i file1
Where i is a switch, removes file1 interactively; i.e. you are asked for confirmation before
deleting the file.
-': $rm r dir1
This command recursively (-r) removes all contents of `dir1 and also `dir1 itself.
rm used with F option removes files forcibly, irrespective of whether you have write
permission to them or not.
1%>%2 ,ena!ing of files)
The mv command renames files. It has two functions:
1. It renames a file (or directory).
2. It moves a group of files to a different directory.
"yn) 3!$ 4sourcefilena!e5 4rena!efile514directoryna!e5
-': $mv s1 t1
Then s1 is renamed as t1.
-': $mv olddir newdir
The mv command also has the power to rename directories. `olddir will be renamed to
`newdir, provided `newdir is not already existing.
-': $mv file1 file2 newdir
On execution of this command `file1 and `file2 are no longer present at their original
location, but are moved to the directory `newdir.
1%>%> To create a directory
The mkdir command is used to create a new directory
"yn) 3!kdir options 4directoryna!e5
-': $ mkdir book
The above command creates a directory named 'book'
Among the options available with mkdir is -p, which allows us to create multiple generations
of directories specified in the given path too.
-': $mkdir -p works/dir1/unix/book
The '-p' option tells Unix to first create works, then within it dir1 next its child directory
UNIX, and lastly book, nested within all these.
-': $mkdir -m 754 newdir
This creates a directory with permissions 754 irrespective of umask value.
1%>%? To re!o$e e!pty directory
"yn) 3r!dir options 4directoryna!e5
The rmdir is used to remove directories.
With '-p' option, it removes not only the specified directory but also its parent directories.
However rmdir removes only the empty directories.
-': $ rmdir -p works/dir1/unix/book
It removes the directory book.
In order to remove the parent directories of book, we say here on removing the book
directory if the Unix directory falls empty then it is removed. On removing the Unix
directory if the dir1 directory falls empty then that too gets removed and so on. This process
stops when rmdir bumps into a non-empty parent directory.
-': $mkdir newdir
$cd newdir
$pwd
/usr/user1/newdir
That is, the current directory is changed to newdir. To get back to the original directory.
$cd
$pwd
/usr/user1
"ecurity by *ile #er!issions) chmod, chgrp, chown, umask.
1%? *ile per!issions)
The permissions signify who all can access the file, and for what purpose. There are three
types of permissions to a file.
r read
w write
x execute
There are three entities to which any combination of these permissions are assigned. These
entities are the owner, the group, and the rest (those outside the group). In ls l, a set of
nine characters denote these permissions of the nine characters, the first three characters
decide the permissions held by the owner of the file. The next set of three characters
specify the permissions for the other users in the group to which the file owner belongs,
while the last set decides the permissions for the users outside the group. Out of the three
characters belonging to each set the first character is for indicating the `read permission,
the second character is for `write permission and the last is for `execute permission. For
example, a file sample has long listing as rwxr-x-x, then
1. The owner can read, write as well as execute the file sample.
1. The members of the group can read and execute the file but can`t write to it. A
`-`indicates that the permission is denied.
1. All others can only execute `sample
These permissions can be encoded numerically. The weights assigned to the three
permissions are
Permission Weight
Read (r) 4
Write (w) 2
Execute(x) 1
Thus, when all three permissions are available, the total weight age or value is 4+2+1 = 7,
as in the case with the owner of `sample
The group permissions of `sample are r-x, hence the value is 4+0+1 = 5. the permissions
for the rest are x, thus the value assigned is 0+0+1 = 1.
Then everybody has all permissions, rwxrwxrwx, they would amount to 777.
The existing file permissions can be changed by the owner of the file or by the super user.
The way to change the permissions is by using chmod command. If `changes the mode of
the file it is executed on. If we want the owner of `sample to have all the permissions,
group and others none, we say
1%?%1 ch!od) changing !ode :per!issions<
The chmod command is used to set the permissions of one or more files for all three
categories of users.
It can be used two ways:
1. In a relative manner by specifying the changes to the current permissions.
2. In an absolute manner by specifying the final permissions.
,elati$e !anner)
The chmod command only changes the permissions specified in the command line and
leaves the other permissions unchanged.
"yn) 3ch!od D;hoE DF1-1GE Dper!issionsE 4filena!e5
The who refers to whom the permissions are to be assigned. It may be the user or owner
(u), the group (g) or others (o). if none is specified, all are assumed. The `+ refers to add
permission, `-` refers to remove permission and `= instructs chmod to add the specified
permission and take away all others, if present.
-': $ chmod a + w sample
It adds write permissions for all users
-': $ chmod go-x sample.
In order to take away execute permission from others as well as group.
-': $ chmod go+r,go-w pack1
This removes write permission for group and others and adds only read permission.
-': $ chmod go=r,u=rw file1
This command remove all existing permissions and replaces them with read permission for
group and others, and read and write permission for owner of the file `file1.
.ctol Notation :(bsolute !anner<)
The expression used by chmod here is a string of three octal numbers read - 4, write 2,
and execute 1
"yn) 3ch!od per!issions 4filena!e5
-': $ chmod 700 sample
This way of changing file permissions is referred to as the absolute mode. It assigns read,
write, and execute permissions for user and no other permissions to group and others.
Instead of using u/g/o and +/-/= we can straightaway use the weight (read=4, write=2,
execute=1) associated with each permission as shown below.
-': $ chmod 741 file1
This would assign the permission rwxr-x-x to `file1.
1%?%& hanging *ile .;nership)
The chown command transfers ownership of a file to a existing user and it seems that it can
optionally change the group as well. The command requires the user-id of the recipient
followed by one or more filenames. Changing ownership requires the super user permission,
to change to super user type su command
$su
Password ***** if entered correct password displays # prompt as shown below
#
"yn) Hcho;n 4ne;o;nerna!e5 4filena!e5
-': #chown it02 add.sh
This change ownership it01 to it02 of add.sh file
1%?%2 hanging group o;ner)
The group owner of a file is the group to which the owner belongs. The chgrp (change
group) command changes a files group owner.
A user can belong to more than one group, and the one shown in /etc/passwd is the users
main group. No super user permission required.
"yn) 3chgrp per!issions 4filena!e5
-':ls l dept.lst
_rw_r__r__ 1 kumar metal 139 jun 8 16:47 dept.lst
$chgrp dba dept.lst; ls -l dept.lst
_rw_r__r__ 1 kumar dba 139 jun 8 16:47 dept.lst
It changes group from metal to dba using chgrp command
#chown sharma:dba dept.lst
It changes ownership to Sharma and group to dba for dept.lst file.
1%?%> Masking *ile #er!issions)
Unix uses the value stored in a variable called umask to decide the default permissions
umask stands for user file creation mask, the term mask implying which permissions to
mask or hide. The umask value tells UNIX which of the three permissions are to denied
rather than granted. The current value of umask can be easily determined by just typing
umask.
"yn) 3u!ask 4defaultper!issions5
-': $umask
0022
Here, the first 0 indicates that what follows is an octal number. The three digits that follow
the first zero refer to the permissions to be denied to the owner, group and others. This
means that for the owner no permission is denied, whereas for both, the group and others
write permission (2) is denied whenever a file is created UNIX assumes that the permissions
for this file should be 666. But since umask value is 022, UNIX subtracts this value from the
default system wide permissions (666) resulting in a value 644. This is the reason why the
permissions turned out to be 644 or rw-r-r-for the file `sample.
Similarly, system wide default permissions for a directory are 777. This means that when
we create a directory its permissions would be 777-022 i.e 755. Execute permission for a
directory has a special significance. If a directory doesnt have an execute permission we
can never enter into it.
We can change current umask value to a new value. For example,
-': $ umask 242
Here onwards any new file that is created would have the permissions 424 (666-242) and
any directory would have the permissions 535 (777-242).
1%@ The UNIX *ile "yste!:
A file system is a group of files and relevant information regarding them. Whole hard disk
may comprise a single file system or it may be portioned to house several file systems. The
disk space allotted to a UNIX file system is made up of 'blocks', each of which are typically
of 512 bytes as well. The block size depends upon how the file system has been
implemented on a particular installation.
The cmchk command is used to find the block size.
-':$ cmchk
BSIZE=1024
All the blocks belonging to the files system are logically divided into 4 parts. The first block
of a file system is called 'Boot block' which is followed by 'super block'. 'Inode Table' &
'Data blocks'.
1%@%1 The Coot Clock)
This represents the beginning of the file system. It contains a program called 'bootstrap
loader'. This program is executed when we 'boot' the host machine. Although only one
boot block is needed to start up the system, all file systems contain one (possibly empty)
boot block.
1%@%& The "uper Clock:
The super block describes the state of the file system how large it is, how many maximum
files it can accommodate, how many more files can be created etc.
1%@%2 The Inode Table)
All entities in UNIX are treated as files. The information related to all these files (not the
contents) is stored in an Inode Table on the disk. For each file, there is an Inode entry in
the table. Batch entry is made up of 64 bytes and contains the relevant details for that file.
These details are:
1. Owner of the file
2. Group to which the owner belongs
3. Type of file
4. File access permissions
5. Date and time of last access
6. Date and time of last modification
7. Number of links to the file
8. Size of the file
9. Addresses of blocks where the file is physically present
1%@%> =ata Clock:
These contain the actual file contents. All allocated block can belong to only one file in the
file system. This block cannot be used for storing any other files contents unless the file to
which it originally belonged is deleted.
1%I Ho; =oes UNIX (ccess *iles)
Internally a file is identified by UNIX by a unique `Inode number associated with it. We can
obtain the inode number associated with a file by using the command ls i.
-': $ls i sample1
sample1 12234
Here 12234 is the inode number. The inode number is an index into the inode table where
the information about the file is stored. For example, amongst several slots present in the
inode table slot number 12234 contains information about the file sample1. Using this
inode number the information about sample1 is accessed from the inode table. The
contents of sample1 file are read from the disk addresses mentioned in the inode entry of
sample1 and displayed on the screen.
1%J "torage .f *iles)
Each inode entry in the inode table consists of 13 addresses each, which specify completely
where the contents of the file are stored on the disk. These addresses may be numbered 0
through 12 of these, the first ten addresses 0-9 point to 1KB blocks on disk. For example, a
file of size 3KB may have its entries as shown in Fig. The address 4970 signifies where the
first 1KBs of the file are stored. The next 1KB chunk is at 5231, and the next at 3401.
4970
Owners
Groups
File type
Permissions
Access time
Modification
time
Inode mode
time
File size
0 4970
1 5231
2 3401
3 7654
4 8675
5 9877
6 7666
7 7441
8 7665
9 8771
10 7777
11 8888
12 9999
5231
3401
Fig1.2:
These addresses may be scattered throughout the disk, as files are stored in chunks
whenever empty blocks of disk are available. This is specially the case with large files, for
which a very big chunk may be impossible. Thus, the addresses 0-9 can handle a file of a
maximum size of 10KB. For files larger than this, Unix has a very interesting way of
indicating their location.
Owners
Groups
File type
Permissions
Access time
Modification
time
Inode mode
time
File size
0 4970
1 5231
2 3401
3 7654
4 8675
5 9877
6 7666
7 7441
8 7665
9 8771
10 7777
11 8888
12 9999
Fig1.3:
As can be seen from the Fig1.3, the 10
th
entry also contains an address of a 1KB block. This
block doesnt contain the file contents. Instead, it consists of 256 ten-byte slots, which can
store 256 more addresses. Each of these 256 addresses can point to 1KB block on disk.
Thus, for a file which occupies 12 blocks on the disk, the first 10 addresses would be found
in the inode entry for this file, whereas address of 11
th
and 12
th
block would be present in a
1KB block whose address in turn is stored as the 11
th
address in the inode entry.
Thus, the maximum file size that can be addressed using the 10
th
address entry is 256KB.
This is called single Indirection.
For a still larger file, Double Indirection is used. The 12
th
address in the inode entry points
to a block of 256 addresses, each of which in turn points to another set of 256 addresses.
These are the addresses of 1KB chunks, making the maximum file size accessible by Double
Indirection equal to 256*256KB, which is 64MB.
For an even larger file Unix uses Triple Indirection. This way, the last address in the inode
entry yields an massive 256*256*256KB that is 16GB.
That means, the maximum file size Unix provides for is the sum of sizes accessible by the
13 addresses that occur in the inode entry. Together, they yield 10KB+256KB+64MB+16GB,
which is more than sufficient for all practical purposes
1%K =isk ,elated o!!ands)
=isk Utilities) df, du, find, ulimit, mount, umount.
1%K%1 ,eporting free space)
If we want to see has much of the disk is being used and what part of it lies free, Unix has
for us a command called df (for disk free). This command reports the free as well as the
used disk space for all the file systems installed on one machine.
"yn) 3df
/(/dev/root): 12970 blocks 27587 i-nodes
We have an our machine only one file system installed, the root file system or simply
/dev/root. df reports the number of free disk blocks and free inodes for this file system.
If we want a more detailed information about disk wage we should say,
-': $df ivt
mount dir file system block used free %used i-used i-free %i-used
/ /dev/root 282098 269146 12952 95% 7410 27854 21%
Now, available blocks and inodes are reported numerically as well as percentages of total
available blocks and inodes. This possibly gives a better idea of how much disk space is
free.
df counts blocks in sizes of 512 bytes irrespective of the actual block size a s reported by
the cmchk command.
1%K%& -sti!ate file space usage)
df reports the disk space available in the file system as a whole where as du reports the disk
space used by specified files and directories. For example,
"yn) 3du
226 ./backup
418 ./fa/backup
1182 ./fa
4 ./check
16 ./dbf
1662
Here du is reporting the number of blocks used by the current directory (denoted by `.) and
these used by sub-directories within the directory.
If we specify a directory then du descends down this directory locating any sub-directories
lying in it and reports the blocks used by the directory and the sub-directories.
-': $du /dev
2 /dev/string
4 /dev/rdsk
2 /dev/mouse
20 /dev
Thus, the no.of blocks occupied by each sub-directory within /dev, as well as those occupied
by /dev are displayed.
If we want only the blocks occupied by the directory and not those occupied by the sub-
directories within in it we can say.
-': $du s /dev
20 /dev
du is often used to single out directories that occupy large amounts of disk
space unused and redundant files and directories can then be eliminated from them, there
by freeing the valuable disk space.
1%K%2 uli!it:
It stands for `user limit and contains a value, which signifies the largest file that can be
created by the user in the file system.
"yn) 3uli!it //the current value of ulimit variable.
2097152
This implies that the user cant create a file whose size is bigger than 2097152 bytes or
2048KB. If we try to create a file bigger than this size, its size would be curtailed to
2048KB and the program creating this file could be aborted.
User can reduce this value by saying.
-': $ulimit 1
Here onwards no file can be created whose size is bigger than 512 bytes. Once reduced this
value remains effective till the user doesnt logout. Thus this change will be effective only
for the current session and the system will return to its default value when you logout.
An ordinary user can only reduce the ulimit value and is never permitted to increase it. A
super user is an exception to the rule and can increase or decrease this value.
1%K%> find)
The find command is recursively examines a directory tree to look for file matching some
criteria, and then takes some action on the selected files or locating files.
"yn) 3find pathlist selectionLcriteria action
-': find / -name a.out print
It will find files from root directory as name of file name a.out after finding file it will display
file content. Otherwise it will display no file found.
selectionLcriteria)
M-na!e 8 Negation :in$erse<
-inu! n 8 identification nu!ber :inode nu!ber<
-per! nnn 8 per!issions
-links n 8 nu!ber of links
-': find / -perm 600 print
It search for files from root directory with permissions for user read, write and no
permissions to group and others.
1%K%? !ount1un!ount:
A super user may extend the file system by using the `mount utility.
"ynta' : mount o options [device name directory]
unmount device name
The file system built on the floppy disk can be linked into the existing file system on the
hard disk using the `mount command. Once mounted we can create files and directories in
the new file system and treat it as a normal directory existing in a file system.
When we use mounting a file system, we are simply attaching its root directory to a
particular point in the existing file system. This point of attachment is called the `mount
point for that file system. The mount point of any new file system, must always be specified
as a path from the root directory of the existing file system. The default one is /mnt.
# /etc/mount /dev/fdo/mnt
/mnt is an empty directory in the root (/) directory, with root (super user) as its owner. All
users have the permission to access this directory.
Option `rw mounts a file system for read\write
Option `ro mounts a file system for read only
The `umount utility unmounts a previously mounted file system.
$mount #lists the currently mounted devices.
/dev/dsk1 on/(rw)
$ls /user #/user is currently empty.
$mount /dev/dsk2 /usr #mount the /dev/dsk2 device
$mount #list the currently mounted device.
/dev/dsk1 on/(rw)
/dev/dsk2 on/usr (rw)
$ls /usr #list the contents of the mounted device
Bin/....
$umount /dev/dsk2 #unmount the device
$mount #list the currently mounted device
/dev/dsk on/(rw)
$ls /usr #/usr is empty again
The files were no longer accessible.
1.10 #rocess ,elated o!!ands
#rocess Utilities) ps, who, w, finger.
1.10.1 ps :$ie;ing the process<)
The ps command used to view all processes that you are responsible for created.
$ps
PID TTY TIME CMD
364 console 0.00 ksh shell running all the time.
This process has a unique number 364 and when you logout, this process is killed. When
you run several programs, there will be multiple lines in the ps output.
1.10.2 ;ho
who command displays details about the users who logged into system.
NAME LINE TIME COMMENTS
ito1 pts/2 2012-10-20 13:37 192.168.0.164
The 1
st
column shows the user names
The 2
nd
column shows the device names of their respective terminal
The 3
rd
column shows the date and time of logging in.
The last column shows the machine name from where the user logged in.
1%1N%2 W:
A command that reports on system usage, logged on users and what they are doing and
the load average. The load average is the average number of processes in the last 1, 5
and 15 minutes.
"ynta' : w [options] username
Normally, w reports on all users, but if you specify username as a comma separated list
of names, the report is restricted to information on just these names.
Ex: $ w
U"-, TT0 *,.M /.OINP I=/- Q#U ##U WH(T
User1 tty1 192.168.0.3 1:24 6.00s 00.12s 00.01s man w
Jcpu The jcpu time is the time consumed by all processes at that terminal. It include
currently running background jobs.
Pcpu Time is used by current process named in what field.
OPTION DESCRIPTION
-h Turns off the report header line.
-l Creates a long listing, including the following columns:
User TTY Login Idle JCPU PCPU what
-q Creates a quick listing that consists of user, TTY, Idle and What
-t Displays only the heading line; equivalent to the o/p from uptime.
1.10.3 finger:
The finger command that tells you which users are connected and which, if any, can receive
messages. It is a more informative tool.
$finger
LOGIN NAME TTY IDLE WHEN AND LOGIN TIME WHERE
henry henry james *1 16 Dec, 27 Fri 8:56 mercury.heavens
1
st
column shows user id.
2
nd
column shows users full name.
3
rd
column shows terminal, preceded by an asterisk ( i.e the terminal doesnt have write
permission).
4
th
column shows the idle time by the user.
The last column shows the name of the machine from where the user logged in.
%plan and %proBect files)
These files makes finger a useful communication tool. Its often necessary to leave behind
your schedule and other important information for others to see, especially if you are going
on vacation. When someone runs finger with userid as argument the contents of these two
files are displayed.
The .plan file can display multiple lines
The .project file can display single line
1.11 Te't ,elated o!!ands

Te't #rocessing Utilities) head, tail, sort, nl, uniq, grep, egrep, fgrep, cut, paste, join,
more, pg, wc, tee, comm, cmp, diff, tr, ln.
1.11.1 head: Displaying the beginning of a file.
-': $head -10 newfile
The first 10 lines of newfile are displayed.
1.11.2 tail: Displaying the end of a file.
The tail command is the counter part of the head command, displays the end of the
file. By default head and tail commands display first and last 10 lines of a file
respectively.
-': $tail -3 emp
It displays the last 3 lines in emp file.
The disadvantage of head and tail is that they cannot display a range of lines.
1%11%2 sort: This command can be used for sorting the contents of a file. Apart form
sorting files, sort can merge multiple sorted files and store the result in the specified output
file. While sorting the sort command bases its comparisons on the first character in each
line in the file. If the first character of two lines is same then the second character in each
line is compared and so on. It sorts the spaces the tabs first, then the punctuation marks
followed by numbers, uppercase letters and lowercase letters in that order.
This simplest form of sort command would be
$sort file1
This would sort the contents of file1 and display the sorted output on the screen.
If we want to sort the contents of several files at one short as in
$sort file1 file2 file3
Instead of displaying the sorted output on the screen we can store it in a file by saying,
$sort oresult file1 file2 file3
The above command sorts the three files file1, file2 and file3 and saves the result in a file
called result.
And if there are repeated lines in each of these files and we want that such lines should
occur only once in the output we can ensure that using u option which output only unique
lines.
$sort u oresult file1 file2 file3
If the files have already been sorted and we just want to merge them we can use:
$sort m file1 file2
If we want to combine the contents of a file with the input from the keyboard and then carry
out the sorting. This can be achieved by saying:
$sort file1
Where `-` stands for the standard input i.e keyboard.
We can even sort only the input from standard input by just saying
$sort
Here, no file name is specified, so it considers input is from standard input device.
Assume that a file student has four fields, for roll number, names of the students, their
marks and their grades. These fields would be numbered 0,1,2 and 3
$sort r +1 -2 students
The +1 indicates that the sort key begins at the second field (i.e names field) and the -2
indicates that it ends before the third field (i.e up to marks field). This yields names of the
students as the sort key.
The r switch indicates a reverse sort. So, the records arranged in reverse alphabetical
order of names could be displayed on the screen.
If we want to sort the same file according to marks we must use n option which specifies
that the sorting is to be done on a numeric field.
The following table shows all the options that can be used with sort.
.ption Meaning
-b Ignores leading spaces and tabs
-c Checks if files are already sorted. If they are, sort does nothing.
-d Sorts in dictionary order (ignores punctuation)
-f Ignores case
-m Merges files that have already been sorted.
-n Sorts in numerical order
-o file Stores output in file. The default is to send output to standard output.
-r Reverse sort
-tc Separates field with character (default is tab)
-u Unique output if merge creates identical lines, uses only the first.
+n[-m] Skips `n fields before sorting and then sorts through field `m.
1%11%> nl) line nu!bering:
This is for numbering the lines.
$nl file1
1 chairman
2 special officer
3 principal
4 head
5 lecturer
nl uses the tab as the delimiter. The w(width) option to specify the width of the number
format, and s(separator) to specify the separator.
$nl w2 s : file1
1: chairman
2: special officer
3: principal
4: head
5: lecturer
The nrz option right- justifies the number, with leading zeros to fill the gaps:
$nl w2 s : file1
01 : chairman
02 : special officer
03 : principal
04 : head
05 : leturer
There are two other options i(increment) option and the v k option that sets the initial
value to k.
1%11%? uniA) locating repeated lines:
$uniq mp1
Uniq simply fetches one copy of each record and writes it to the standard output.
Like sort, uniq also accepts the output filename as an argument. Uniq uses only one
filename at a time. If three filenames are given, then uniq simply processes the first file and
overwrites the second with its output.
If uniq is to merely select uniq lines, it is preferable to use sort u that does this job with a
single command. Uniq has a couple of useful options; they can be used to make simple
database queries. The u(unique) option selects only the non-repeated lines. The
d(duplicate) option selects only one copy of the repeated lines. And c (count) option
displays the frequency of occurrence of all lines, along with the lines.
When uniq is used with other filters like cut and sort acts as a database tool to query the
database ie to retrieve information from database.
1%11%@ grep: `grep is an acronym for global search a regular expression and print it. The
command searches the specified input fully (globally) for a match with the specified pattern
and displays it. While forming the patterns to be searched we can use shell meta
characters, or regular expressions like `, `? `[] `!.
1) $grep picture newfile
This would search the word `picture in the file newfile and if found the lines
containing it would be displayed on screen. We can use grep to search a
pattern in several files.
For example:
$grep picture newfile file1
Here, the word `picture would be searched in both the files, newfile and file1 and if found,
the lines containing it would be displayed along with the name of the file where it occurred.
For a search pattern comprising more than a single word, single quotes can be used to
enclose the same as in.
$grep `the picture taken i n newfile file1
The above command searches for the pattern enclosed within ` `, without heeding the case
(-I makes it case insensitive). The `-n option also causes the number of lines in which the
pattern was found to be printed by the side of each line.
$grep [Rr]ain file2
Here grep would search for all occurrences of `Rain as well as `rain in file2 and display the
lines which contain one of these words.
$grep b??k file2
This command would display all four-letter words whose first letter is a `b and last letter, a
`k. The two `? symbols represent one character each.
$grep v a* file2
All those lines that dont contain words starting with `a are displayed.
`^[abc] would help to search only those lines which begin with `a, `b or `c.
`[s-z]$ would help to search those lines which end with any character between `s to
`z.
The various options available with `grep are shown bellow.
.#TI.N M-(NINO
-c Returns only the number of matches, without quoting the text.
-i Ignores case while searching
-l Returns only filenames containing a match, without quoting the text.
-n Returns line number of matched text, as well as the text itself
-s suppresses error messages
-v Returns lines that dont match the text
1%11%I egrep) -'tending grep:
The egrep command, extends greps pattern-capabilities. It offers all the options of grep,
but its most useful feature is the facility to specify more than one pattern for search. Each
pattern is separated from the other by a |(pipe).
-'pressions and their significance:
chF : Matches one or more occurrences of character ch.
ch? : Matches zero or one occurrence of character ch.
e'p1Re'p& : Matches expression exp1 or exp2.
:'1R'&<'2 : Matches expression x1x3 or x2x3.
The above are not used with grep.
For example, b+ matches b, bb, bbb etc while b? matches either nothing or a single b.
$egrep i `agg?[ar]+wal emp
`-i indicates case insensitive.
"earching for !ultiple patterns:
$egrep `Renigunta|Panjagutta emp
`| is separator of the patterns.
$egrep `(sen|das)gupta emp
$cat file1
admin/accounts/sales
$egrep f file1 file2
This command searches for patterns for file1 in file2.
1%11%J fgrep ) Multiple string searching:
fgrep like egrep accepts multiple patterns, both from the command line and a file, but unlike
grep and egrep, doesnot accept regular expressions. So, if the pattern to search for is a
simple string, or a group of them, fgrep is recommended. It is faster than grep and egrep.
Alternative patterns in fgrep are specified by separating one pattern from another by the
new line character.
-' : $cat ex1
Sales
Personnel
Admin
$fgrep f ex1 ex2
1%11%K cut: Like sort, cut is also a filter. It cuts or picks up a given number of character or
fields from the specified file cut is slitting a file vertically cut identifies both columns and
fields.
-': a) $cut c 5-10 16-20 file1
Displays the columns from 5 to 10 and 16 to 20 of file1
b) $cut c -3 5-10 16-20 30- file1
The expression 30- indicates column number 30 to the end of the line. Similarly, -3
is the same as 1-3.
Files often dont contain fixed length records, in which case, it is better to cut fields rather
than columns. Two options need to be used here d (delimiter) for the field delimiter and f
(field) for specifying the field list.
-': $cut f 2,7 empinfo
Here, 2
nd
and 7
th
field of empinfo are displayed.
If we are to view fields 2 through 7 we can say
$cut f 2-7 empinfo
The cut command assumes that the fields are separated by tab character. If the fields are
delimited by some character other than the default tab character, cut supports an option d
which allows us to set the delimiter. The file empinfo may have the information for each
employee stored in the following format:
name: age: address: city: pin: division
Each piece of information is separated by a colon, hence we require the field delimiter to be
recognized as `:. The command for listing the name and division fields would now be.
$cut f 2,7 d : empinfo
1%11%1N paste) pasting files)
It is a special type of `concatenation in that it pastes files vertically rather than horizontally.
$ paste file1 file2
Then the fields of file2 are concatenated to fields of file1. By default the delimiter is tab. The
delimiter of our choice is set by `-d(delimiter) option.
$cut d | f 1,4 shortlist | paste d | cutlist
1%11%11 Qoin:
A command that extracts common lines from two sorted files.
"ynta' : join [options] filename1 filename2
One line of o/p is created for each line in the two files that match, based on option.
This command joins the common lines found in filename1 and filename2; if filename1 is not
specified, oin reads from the standard input.
OPTION DESCRIPTION
-a n Lists un matched lines from file `n or from both if `n is
omitted.
-e string Replaces any empty field with `string.
-jn n Joins the two files on the m
th
field of file n; if `n is not
specified, the files are joined on the m
th
field of both files.
-on.m Specifies the fields to o/p from each file for each line for each
line with matching join fields, where `n specifies the file
number and `m specifies the field number.
-t char Uses character `char as a field separator for i/p and o/p.
1%11%1& pg and !ore) Unix provides two commands, which offer more flexibility in viewing
files. These are pg and !ore% Each of them is used to display page by page with following
options:
Set the number of lines to be displayed per page.
Ability to move either forward or backward in a file just at the touch of a key.
Skip pages while viewing the file page by page.
Search the file for a pattern in forward or backward direction.
-': $pg +10 -15 p page no.%d s myfile
This command starts displaying the contents of m!file,15 lines at a time from 10
th
line
onwards. At the end of each displayed page, a prompt comes which displays the page
number on view.
This prompt overrides the default `: prompt of the pg command. The `-s option ensures
that the prompt is displayed in reverse video.
$more +10 -15 s d myfile yourfile
This is also similar to pg command. The difference being it could display contents of two files
m!file and !ourfile" Also, the `-s option could squeeze multiple blank lines in a file to a
single blank line. The `-d option changes the normal --more-- prompt displayed at the end
of each page to a more explanatory `[hit space to continue, delete to abort].
The most obvious difference between pg and more is , pg permits us to set the prompt
whereas more doesnt. Also, while using more at the end of each page a number appears
which indicates how much percentage of file have we viewed so far.
1%11%12 ;c:
It counts the number of lines, words and characters in the specified file or files. It comes
with the options -l# -w and c which allow the user to obtain the number of lines, words or
characters individually or in any desired combination.
-': $wc lc file1 file2
file1 20 571
file2 30 804
The file file1 constitutes 20 lines and 571 characters similarly for the file2.
The wc command is capable of accepting input directly from the keyboard. By entering wc
without any arguments, it waits for the user to type in the input. On terminating input
(using ctrl d), the appropriate counts are displayed for the input.
Note) *ilters are) cat, pg, more, head, tail, grep, sort, wc, nl, uniq, cut, paste etc%
1%11%1> I1. ,edirection and #iping+ tee:
Unless otherwise instructed Unix commands\programs get their input from standard input
device and send their output to the standard output device. Any error messages if they
occur are sent to the standard error device.
Thus, if a command is described as reading from the standard input and writing to the
standard output, that means it takes input from keyboard and sends output or error
messages to the screen. The three streams, ie the standard input, standard output and the
standard error are denoted by the numbers 0,1,2 respectively.
"trea! =e$ice Salue
Standard i/p Keyboard 0
Standard o/p Terminal screen 1
Standard error Terminal screen 2
It is useful to redirect the i/p or o/p to a file or a printer. The symbol > implies redirection of
output and the symbol < implies redirection of input. The symbol > sends the o/p of a
command to a file or a device, such as a printer. The symbol < takes the i/p needed for a
command from a file rather than from the keyboard. The symbol >> adds o/p from a
command to the end of a file without deleting the information in the file.
1) $cat file1>file2
The redirection operator declares file$ to the standard output. Thus the output of cat
which is normally sent to the screen is now sent to file2 and not to the screen. If
file2 doesnot exist, it is created. If it already exists, it s contents are overwritten
with file1 content.
2) $cat
Input is from keyboard.
$cat< newfile
Chennai is the capital of Tamilnadu.
Then
$cat newfile
Chennai is the capital of Tamilnadu.
$cat newfile
Hyderabad is the capital of Andhra pradesh.
ctrl d
Chennai is the capital of Tamilnadu.
Hyderabad is the capital of Andhra Pradesh.
`- is the keyboard input.
3) $cat< file1 >newfile
The first part of redirection, % file&, indicates that input is to be taken from the file
'file&( and the second part of redirection, )newfile establishes that o/p is to be
routed to the file newfile.
The order in which the two indirection operators are used doesnot matter. The same thing is
represented as follows:
$cat > newfile < file1
Another redirection operator which is popularly used is the append operator,)). It is similar
to >, except if the target file already exists, the new output is appended to its end.
For example,
$who >> logfile
This command appends the current list of users who have logged into the end of the file
logfile.
.perator (ction
> file Make `file the standard output
< file Make `file the standard input
>>file Make `file the standard output, appending to it
if it already exists.
<< word Take shell input up to the first line containing
Word or up to end of file.
n >file Make file the output for file descriptor n.
1>&2 Redirect standard output to standard error.
cmd1|cmd2 Make standard output of cmd1, the standard
input of cmd2.
#iping:
Through redirection facility commands can be connected to files. The Unix piping facility
connects commands to other commands. This facility is of utmost importance in combining
Unix commands and operations. It can be really useful to redirect the output of one
program and that it becomes the input of another program, there by joining the two
programs. To send the output one command as input for another, the two commands must
be joined using a pipe (|) character.
It is possible to join commands using a pipe since many Unix commands accept input from
the standard input and send output to the standard output. Incidentally such commands are
known as filters.
Thus a filter is a program, which can receive a flow of data from standard input, process (or
filter) it, and send the result to the standard output.
-': $ls | wc -l
Here, the output of ls becomes the input to the wc which promptly counts the number of
lines it receives as input and displays this count on the screen. Instead of displaying this
count, we can store the result in a file as shown below:
(with output redirection)
$ls | wc l >countfile
Here, both piping and redirection are used.
-': $who | sort
Here, instead of displaying the output of who on the screen it is piped to sort. *ort sorts
whatever it receives as input(output of who, in this case) and displays the sorted
output(sorted according to first character in each line) on the screen. Because sort being a
filter unless otherwise mentioned it sends the output to the screen. We can redirect sorted
output to a file by
$ who | sort >sorted list
-': $who | sort logfile >newfile
The output from who becomes the standard input to sort. Meanwhile, sort opens the file
logfile. The contents of this file are sorted together with the output of who(represented by
the hyphen) and the sorted output is redirected to the file newfile.
Redirection routes the output to files while pipes route the output to other
programs(commands). Unix offers tee command to achieve both. It reads the standard
input and sends it on to the standard output.
-': who | tee logfile | sort
Here, the output of who becomes the standard input of tee. tee now sends one copy of the
input to sort through one pipeline, whereas the other copy is stored in a file called logfile.
$who | tee file1 file2 | sort
Here, the output of who is stored in file& and file$ and one copy is sent to sort.
If we want to store the output of who in file& and file$, display the same output on the
screen and store the sorted output in file+, then we write
$who | tee file1 file2 /dev/tty3a | sort >file3
If we wish to append the output of tee to a file, -a option is used with it as shown below:
$cat file1 file2 | tee a file3 | more
In this pipeline the output of cat(contents of the files file& and file$) are appended to the
existing contents of file+. Another copy of output of cat is sent to more for displaying on the
screen.
So far we have redirected only the standard input and the standard output. We can however
also redirect the standard error. The following example shows this:
$cat myfile >newfile 2 >errorfile
If the file m!file exists, then the contents that file would be copied to newfile. However if it
doesnot exist, then an error message would be produced. However instead of displaying the
error message on the screen, it would be redirected to a file errorfile. The > symbol
redirects the standard output whereas 2 > redirects the standard error. While redirecting
the standard output instead of > we we may also well use 1 >.
1%11%1? co!!)finding ;hat is co!!on)
comm requires two sorted files, and compares each line of the first file with its
corresponding line in the second.
Ex : $cat file1 $cat file2 $cat file3
Raghu.V Varun.T Raghu.V
Shiva.P Tharun.Q Shiva.P
Roja.R Raghu.V Gopi.N
Gopi.S Roja.R Sekhar.S
$comm file1 file3
Raghu.V
Shiva.P
Gopi.N
Roja.R
Gopi.S Sekhar.S
comm can also produce selective output, using options -&# -$ or -+. To drop a particular
column, simply use its column number with the `-` sign. We can also combine options and
display only those lines that are common.
$comm -3 file1 file2 $comm -12 file1 file2
1%11%1@ c!p) co!paring t;o files:
Whether two files are identical or not is determined through cmp# diff and comm.
commands.
$cmp chap1 chap2
chap1 chap2 differ :char 9,line1
The two files are compared byte by byte and the location of the first mismatch(in the 9
th

character of first line) is echoed to the screen. cmp, when invoked without options, doesnot
bother about possible subsequent mismatches.
The l(list) option gives a detailed list of the byte number and the differing bytes in octal for
each character that differs in both files:
$cmp l file1 file3
17 162 147
.
.
.
.
30 12 56
If the two files are identical, cmp displays no message, but simply returns the $ prompt.
1%11%1I diff) con$erting one file to other:
diff is used to display file differences. It tells us which lines in one file have to be changed to
make the two files identical.
$diff file1 file3
3,4c3,4 #change line 3 of file1
< roja.r #}replace these
< gopi.s #}lines
- - - - - #with
> gopi.n #}these
> sekhar.s #}two lines
diff uses certain special symbols and instructions to indicate the changes that are required
to make two files identical.
Maintaining several versions of a file: diff has an extremely useful option for the system
administrator the e option. If we have ten versions of a file differing only nominally, we
now need to keep only one in full. For the others, we can keep only the differences, which
help us conserve disk space.
1%11%1J tr :translate<:
The tr (translate) command is a simple filter designed to replace one or more characters in
given files with one or more characters. The syntax is:
tr [-cds] [in-string] [out-string]
The `-s option substitutes all of the specified characters with another specified character
and displays the results.
-': $cat items To substitute `z s for al `s,
Shoes $tr Ss Z < items
Socks Zhoes
pants Zocks
Pants
The `-d option deletes characters specified in the given file and displays the results.
$tr d s < items
hoe
ock
pant
The `-c option tells tr not to match the specified characters. It is used with the `-s and `-d
options to modify that those options operate.
-': $tr cd s < items
Ss Here, it will delete all characters except `s.
Ss
s
Without any options, tr does a straight substitution.
$tr o ` < items
Sh es Here, all os are replaced with spaces.
S cks
Pants
Characters can be replaced with ; & ( ) | ^ < > new line and tab, but these must be
specified in single quotes.
$tr `[a-z] `[A-Z] < items
Shoes
Socks
Pants
1%11%1K ln )
The ln command is used to linking two files (directories). There are two types of links
Hard links
Soft links
Hard /inks)
A file is linked with the ln command, which takes two file names as arguments.
$ ln emp employee
$ls li emp employee
INODE PERMISSIONS NO.OFLINKS USERNAME GROUPNAME SIZE DATE&TIME FILENAME
29518 _rwxr_wr_w 2 kumar metal 915 may 4:9:58 emp.lst
29518 _rwxr_wr_w 2 kumar metal 915 may 4:9:58 employee.lst
The link count which is normally one for unlinked files, above shows as two for two files
linked. The number of links increase by one if one more file linked.
The rm / ulink command removes a file by removing its directory entry. The link count is
decreased by one.
When do you reAuire to link files?
1. Links provide some protection against accidental deletion especially when they exist
in different directories. By creating a link, you create a backup. So, even if you
inadvertently delete one link, another will still be available.
2. Because of links, we dont need to maintain two programs as two separate disk files
if there is very little difference between them.
T;o li!itations in hard links)
Cant link two files in two different file systems.
Cant link a directory even within the same file system.
"y!bolic /inks)
To overcome the limitations of hard links use symbolic links. A symbolic doesnt have the
files contents but simply provides the pathname of the file that actually has the contents.
$ ln s raju raju1
29518 _rwxr_wr_w 1 kumar metal 915 may 4:9:58 raju.lst
29519 _rwxr_wr_w 1 kumar metal 915 may 4:9:58 raju -> raju1.lst
1%11%&N a;k:
`awk got its name from the combined first letters of its authors surnames. Aho,
Weinberger and Kernighan. It borrows its control structures and expression syntax from the
C language.
The awk programming language is also known as pattern scanning and processing
language.
"ynta': awk FC [-f filename] program {variable=value}*{filename}*
`awk is a programmable text-processing utility that scans the lines of its i/p and performs
actions on every line that matches a particular criteria. An 'awk( program may be included
on the command line, in which case it should be surrounded by single quotes; alternatively,
it may be stored in a file and specified using the `-f option. The initial values of variables
may be specified on the command line. The default separators are tabs and spaces. To
override the default, use the `-F option followed by the new field separator. If no filenames
are specified 'awk( reads from standard input.
An 'awk( program is a list of one or more commands of the form [condition] [\ {action \}]
Where condition is either,
the special token BEGIN or END or
an expression involving any combination of logical operators, relational operators and
regular expressions and `action is a set of one or more of the following kinds of C-
like statements, terminated by semicolons:
if (condition) statement [else statement]
while (conditional) statement
for (expression; conditional; expression) statement
break
continue
variable=expression
print [list of expressions] [> expression]
printf format [list of expressions] [> expression]
next (skips the remaining pattern on the current line of the i/p)
exit (skips the root of the current line)
{list of statements}
`action is performed on every line that matches `condition( . If condition is missing, action is
performed on every line. If action is missing, then all matching lines are simply sent to
standard o/p. The statements in an `awk program may be indented and formatted using
spaces, tabs and new lines.
(ccessing indi$idual fields:
The first field of the current line may be accessed by $1, the second by $2 and so forth. $0
stands for the entire line. The built-in variable `NF is equal to the number of fields in the
current line.
-': $cat float #look at the original file(float is a text file)
This is UNIX command
Programming commands are available in UNIX
$awk `{print NF,$0} float #execute the command
.utput:
4 This is UNIX command
6 Programming commands are available in UNIX
Cegin and end:
The special condition BEGIN is triggered before the first line is read, and the special
condition END is triggered after the last line has been read. When expressions are listed in a
print statement, no space is placed between them, and a new line is printed by default. The
built-in variable FILENAME is equal to the name of the i/p file.
$cat awk2 #look at the awk script
BEGIN{print start of file:, FILENAME}
{print $1 $3 $NF} #print 1
st
, 3
rd
and last fields
END{print End of file}
$awk f awk2 float #execute the script
.utput:
Start of file:float
This is unix command
Programming commands are available in unix
End of file
.perators:
When commas are placed between the expressions in a `print statement, a space is printed.
All of the usual C operators are available in `awk. The built-in variable `NR contains the line
number of the current line.
$cat awk3 #look at the awk script
NR>1 && NR<4 {print NR,$1,$3,$NF}
$awk f awk3 file1 #execute the script
.utput:
2 sree engg
3 dept information
Where,
$cat file1
There are 60 students in IT-A
Sree vidyanikethan Engg College A.Rangampet
Dept of Information Technology
Advanced Unix programming
Sariables:
`awk supports user-defined variables. There is no need to declare a variable. A variables
initial value is a null string or zero, depending on how we use the variable.
The following program counts the number of lines and words in a file as it echoed the lines
to the standard output.
$cat awk4 #look at the awk script
BEGIN {print Scanning file}
{
printf line %d: %s \n,NR,$0;
linecount++;
wordcount+=NF;
}
END {printf lines=%d,words=%d\n,linecount,wordcount}
$awk f awk4 file1 #execute the script
.utput:
Scanning file
line1 : There are 60 students in IT-A
line2 : Sree Vidyanikethan Engg College A.Rangampet
line3 : Dept of Information Technology
line4 : Advanced Unix programming
lines=4 words=18
control structures:
`awk supports most of the standard `C control structures.
-':
$cat awk5 #look at the awk script
{
for(i=NF ; i >=1 ; i--)
printf %s,$i
printf \n;
}
$awk f awk5 file1 #execute the script
IT-A in students 60 are there
A.Rangampet College Engg Vidyanikethan Sree
Technology Information of Dept
programming Unix Advanced
-'tended regular e'pressions:
Regular expressions must be placed between slashes(/).
The following example displays all of the lines that contain a t followed by an `e, with any
number of characters in between.
$cat awk6 #look at the script
/t. *e/ {print $0}
$awk f awk6 file1 #execute the script
.utput:
There are 60 students in IT-A
Sree Vidyanikethan Engg College A.Rangampet
Dept of Information Technology
ondition ranges:
A condition range may be two expressions separated by a comma. In this case `awk
performs `action on every line from the first line that matches the first condition to the next
line that satisfies the second condition.
-' :
$cat awk7 #look at the awk script
/Sree/ , /Dept/ {print $0}
$awk f awk7 file1 #execute the script
.utput:
Sree Vidyanikethan Engg College A.Rangampet
Dept of Information Technology
*ield separators:
If the field separators are not the spaces, use `-F option to specify the separator character
-' :
Assume that fields are separated by colons:
$cat awk3 #look at the awk script
NR > 1 && NR < 4 {print $1,$3,$NF}
$cat float2 #look at the input file
Wish: I : was : floating : in : blue : across : the : sky
My : imagination : is : strong
And : I : often : visit : the : days
When : everything : seemed : so : clear
Now : I : wonder : that : Im doing : here : at : all
$awk F : -f awk3 float2 #execute the script
.utput:
My is strong
And often days
Cuilt-in functions:
'awk( supports several built-in functions, including exp(), log(), sqrt(), int() and substr().
The substr(str,x,y) function returns the substring of `str from the xth character and
extending y characters.
1%1& $i
vi (short for visual editor) displays a window of text. The window shows a certain portion of
the edit buffer, and we can position the window to view any part of the buffer.
Changes to the text take place at the cursor position. The editor allows us to move the
cursor around in the edit buffer window easily. For instance, the cursor may be moved
forward or backward a character, a word, a sentence or a paragraph or it may be moved
vertically, up, or down the page.
The visual editor commands have a uniform and consistent structure that makes the
commands easier to learn. Many operations- for example, an operation in which yoy would
change or delete text- may be combined in a natural way with the cursor motion directives
to form a combined command.
There are three editors: ed# e, and vi"
The ed program is basically a line editor, which means that ed assigns line numbers to the
lines in the file; every time you do something, you must tell ed which line or lines to do it
to.
An improved version of ed is e,, understands all the commands of ed.
Compared to ed or e, the vi text editor, is better. It is a screen editor rather than line
editor; it shows you as much of the file as it can fit on the screen.
1%1&%1 =isad$antages of $i)
1. There is no self-explanatory error messages.
2. There is no online help for the programmer.
3. There are three modes in which the editor works. Under each mode the same key
press creates a different effects. Hence meaning of several keys and their effects in
each mode have to be memorized.
4. vi is case sensitive.
Modes of operation:
The vi program has three modes of operation :
1. o!!and !ode: In this mode all the keys pressed by the user are interpreted to
be editor commands. For example, if you hit a `h the cursor is moved one position to
the left. In command mode the keys that are hit are not displayed on the screen.
2. Insert !ode: This mode permits insertion of new text, editing of existing text or
replacement of existing text. Each of these operations can be performed only after
changing over from the command mode to insertion mode using appropriate
commands. The insertion mode is also known as input text mode.
3. e' co!!and !ode: This mode permits us to give commands at the command line.
The bottom line of the vi screen is called the command line. Vi uses the command
line to display messages and commands. All commands entered in the ex command
mode are displayed in the command line. This mode is so called because commands
given in this mode are compatible with commands of the e, editor.
1%1&%& In$oking $i fro! the shell:
$vi filename
To invoke more than one file,
$vi filename1 filename2 . . . . . .
If file already exists, then contents are displayed on the screen, if not it is created.
$vi letter
When we type the vi command and the filename, vi clears the screen and displays a window
in which we can enter and edit text. The _ (underscore) on the top line shows the cursor,
when we enter the command. Every other line is marked with a ~ (tilde) the symbol for an
empty line.
If we have successfully entered vi, we are in command mode and vi waits for commands.
To add text to the file letter:
2 Press the `i key to enter the insert mode of vi. Now we can add text to the file.
3 Press the Esc key to leave the insert mode and return to the command mode.
4 To save this, hold down the shift key and press `Z twice (ZZ). At the bottom of the
screen, the file name and the number of lines and characters in the file are displayed.
(or)
5 Instead of using ZZ to save and quit we can also use :w and :q commands for writing
and quitting a file. The :w command writes the buffer to a file. The :q command leaves
the editor and returns to the shell. These two can be combined as :wq.
1%1&%2 -diting the te't:
To move the cursor on the screen, there are four keys:
h : moves the cursor one character to the left.
l : moves the cursor one character to the right.
B : moves the cursor down one line.
k : moves the cursor up one line.
The and k commands maintain the column position of the cursor.
Instead of pressing l two times to move the cursor two spaces right, we can enter $l. We
can move as many spaces, or lines as we desire. If that place falls outside the current
window that part will be scrolled. If that space does not exist vi will sound to bell.
(dding te't:
To add the text at the end of the file, first position the cursor on the last character in the file
by using cursor movement keys. Next, hit an `a (append) to switch from command mode
to text-input mode.
If we want to add the text at the middle, instead of at the end, then press `i (to insert text
before the current cursor position). If characters are typed then they will be added to the
left of the current cursor position. The vi editor will continue to accept the characters until
Esc key is pressed.
Ho; to delete te't:
If we want to delete a character, move the cursor to that character and press the ,"
': delete one character
n': delete `n characters, where `n is the number of characters you want to delete.
vi adjusts the text so that no gap appears in place of the deleted string.
.$er;riting te't:
If we want to overwrite the existing text then first position the cursor (using h, j, k, l) at the
character from where you want overwriting to begin. Next hit a `R (a capital R) to indicate
that whatever you type next should overwrite the existing text at the current cursor
position. Press Esc when you finish replacing text.
To make undo for most recent change or deletion type an `u. Capital `U undo all the
changes to the current line since you moved the cursor to that line.
Tuitting $i:
To save the document and quit press `ZZ in the command mode or `:wq in ex command
mode. If you decide to quit and not save the changes you have made, type `:q! in e,
command mode and then press Enter.
*ind and ,eplace:
.MM(N= *UNTI.N
:s/str1/str2 Replaces first occurrence of str& with str$ in current line.
:s/str1/str2/g Replaces all occurrences of str& with str$ in the current
line.
:m,n s/str1/str2/g Replaces all occurrences of str& with str$ from lines m to
n.
:1,$ s/str1/str2/g Replaces all occurrences of str& with str$ from the 1
st
line
to the end of the file.
:1,. s/str1/str2/g Replaces all the occurrences of str& with str$ from the first
line to the current line.
:.,$ s/str1/str2/g Replaces all the occurrences of str& with str$ from the
current line to the end of the file.
=elete and #aste:
.MM(N= *UNTI.N
xdd Deletes current line and copies it to a buffer named x. (x
can be any alphabet).
xndd Deletes `n lines from current line and copies them to a
buffer named x.
xdw Deletes current word and copies it to a buffer named x.
xndw Deletes `n words from current cursor position and copies
to a buffer named x.
xp Pastes contents of buffer x at current cursor position.
0ank and #aste:
.MM(N= *UNTI.N
Yw Yanks word from cursor position.
Yy Yanks line from cursor position.
y$ Yanks line from cursor position to the end of line.
y0 Yanks line from cursor position to the beginning of the line.
Lp Pastes last yanked buffer.
Zp Pastes last but one yanked buffer.
xyy Yanks current line to a buffer named x (x can be any
alphabet).
xnyy Yanks `n lines from current line to a buffer named x.
xyw Yanks current word to a buffer named x.
xnyw Yanks `n words from current cursor position to a buffer
named `x.
xp Pastes content of buffer `x at current cursor position.
"et co!!ands:
)set nu : Set display of line numbers on.
)set nonu : Set display of line numbers off(default).
)set eb : Beep the speaker when an error occurs(default).
)set noeb : Dont beep the speaker when an error occurs.
Cackup Utilities cpio, tar.
1%12%1 cpio ) opy Input-.utput:
The cpio command (copy input-output) can be used to copy files to and from a backup
device. It uses standard input to take the list of file names, and then copies them with the
contents and headers, into a single archive that is written to the standard output. This
means that cpio can be used with redirection and piping. It uses two `key options,
-o(output) and i(input) either of which must be there in the command line. Other options
have to be used with either of these key options.
Cacking up files:
`ls can be used to generate a list of filenames for 'cpio( to use as input. The `-o key option
is used to create an archive, which can then be redirected to a device file. This is how we
copy files in the current directory to a floppy:
#ls | cpio ov > /dev/rdsk/fo
array.pl
calendar
276 blocks
The `-v option makes 'cpio( operate in the verbose mode, so that the filename is seen on
the terminal when it is being copied. What 'cpio( needs as input is a list of files to be backed
up, with one file in each line. If this list is available in a file, redirection can be used as,
#cpio o > /dev/rdsk/fo < file1
Incre!ental backups:
'find( can also produce a file list, so any files that satisfy its selection criteria can also be
backed up. We will frequently need to use 'find( and 'cpio( in combination to back up
selected files, for instance, those that have been modified.
find . type f mtime -2 print | cpio ovB > /dev/rdsk/fo
Since the path list of 'find( is a dot, the files are backed up with their relative pathnames.
However if it is a /, absolute pathnames are used.
The `-B option sets the block size to 5120 bytes for input and output, which is 10 times the
default size. For higher (or lower) sizes, the `-C option has to be used.
#ls *. Pl | cpio ovC 51200 > /dev/rdsk/fo
Multi-$olu!e backups:
When the created archive in the backup device is larger than the capacity of the device,
'cpio( prompts for inserting a new diskette into the drive:
#find . type f print | cpio ocB > /dev/rdsk/fo
Reached end of the medium on output.
If you want to go on, type devive/filename when ready
/dev/fdo #device name entered here
3672 blocks
,estoring files:
A complete archive or selected files can be restored with the `-i key option. To restore all
the files that can be backed up with a previous 'cpio( command, the shells redirection
operator (<) must be used to take input from the device.
#cpio iv < /dev/rdsk/fo
array.pl
calendar
276 blocks
To restore sub-directories `-d option is used.
'cpio( accepts a quoted wild-card pattern, so that multiple files fitting the pattern can be
restored. Restoring only the shell script becomes quite easy.
cpio i *.sh < /dev/rdsk/fo
.ther options:
There are 3 important options that can be used with both the `-o and `-i modes:
The `-x (rename) option lets you rename each file before starting the copying
process. The system presents each filename, and prompts you for a response. If you
enter a filename, copying is done to that file; a null response leaves the file
uncopied.
The `-f option, followed by an expression, causes 'cpio( to select all files except those
in the expression:
cpio ivf *.c < /dev/rdsk/fo # restores all except C programs.
The `-c option tells 'cpio( to use ASCII characters, rather than the binary format, for
creating headers.
=isplaying the archi$e:
The `-t option displays the contents of the device without restoring the files. This option
must be combined with the `-i key option:
#cpio itv < /dev/rdsk/fo
100755 henry 605 oct 18 23:34:07 2005 file1.pl
. . . . . . . .
. . . . . . . .
. . . . . . . .
cpio non-key options :to be used ;ith 8i or 8o<
OPTION SIGNIFICANCE
-d Creates directories as when needed.
-c Writes header information in ASCII characters for portability.
-r Rename files in interactive manner.
-t Lists files in archive.
-u Overwrites newer file with older version.
-v Verbose option prints list of files that are being copied.
-m Retains original file modification time.
-f exp Copies all files except those in exp.
-C size Sets input-output block size to size option.
1%12%& tar ) The tape archi$e progra!:
The tar (tape archive) command has been in existence before the emergence of cpio. It not
only creates archives on tapes, but supports floppies as well. Unlike cpio, tar does not write
to the standard output, but creates an archive in the media. It is a versatile command with
certain exclusive features not found in cpio. Some of them are:
It does not use standard input to obtain its file list. tar accepts file and directory
names as arguments.
It copies one or more entire directory trees, i.e it operates recursively.
It can create several versions of the same file in a single archive.
It can append to an archive without overwriting the entire archive.
tar is used with a number of key options- the common ones are c(copy), -x(extract), and
t(list). One and only one of these options has to be present. The `-f option additionally has
to be used for specifying the device name.
Cacking up files:
tar accepts directory and filenames directly on the command line. The c key option is used
to copy files to the backup device:
#tar cvf /dev/rdsk/fo /home/sales/SQL/* .sql
a /home/sales/SQL/invoice -all.sql 1 tape blocks
a /home/sales/SQL/load2 all.sql 10 tape blocks
This backs up all SQL scripts with their absolute pathnames to the floppy diskette. The
single character a before each pathname indicates that the file is appended. (when restoring
files,the character `x is seen in this option). The verbose option (-v) shows the number of
blocks used by each file.
When files are copied in this way with absolute pathnames, the same restrictions apply;
they can only be restored in the same directory. However, if you choose to keep the option
open for installing the files in a different, then you should first cd to /home/sales/SQL, and
then use a relative pathname:
cd /home/sales/SQL
tar cvf /dev/fo . / *.sql
The command will also execute faster if used with a block size of 18 (i.e 18*512 bytes):
tar cvfb /dev/rdsk/fo 18 *.sql
Since both `-f and `-b each have to be followed by an argument, the first word
(/dev/rdsk/fo) after option string cvfb will denote the argument for f, and the second (18)
will line up with `-b.
The advantage of tar lies in that it can copy an entire directory tree with all its sub-
directories. The current directory can backed up with or without the hidden files:
tar cvfb /dev/rdsk/fo 18 * #doesnot backup hidden files.
tar cvfb /dev/fdo 18 . #backs up hidden files.
The files here are backed up with their relative pathnames, assuming that they all fit in one
diskette.
Multi-$olu!e backup:
For multi-volume diskette back ups, tar uses a special option(-k), followed by the volume
size in kilo bytes.
#tar cvfkb /dev/rdsk/fo 1440 18 index1
Volume ends at 1439k, blocking factor=18
tar: large file index needs 2 extents
tar: current device seek position=ok
+++a index 1439k [extent #1 of 2]
'tar( estimates that two 1440kB(the argument of k) diskettes will be required. After the
first volume is full, `tar prompts for a new volume:
tar: please insert new volume, then press RETURN
tar options:
OPTION SIGNIFICANCE(key options)
-c Creates a new archive.
-x Extracts files from archive.
-t Lists contents of archive.
-r Replaces files at end of archive.
-u Like r, but only if files are newer than those in archive.

OPTION SIGNIFICANCE(NON-KEY OPTIONS)
-v Verbose option lists files in long format.
-w Confirms from user about action to be taken.
-f dvc Uses the pathname dvc as name of device instead of the default.
-b n Uses blocking factor n, where n is restricted to 20.
-m Changes modification time of file to time of extraction.
-k num Multi-volume back up- sets size of volume to num kilobyte.
-M Multi-volume back up.
-z Compresses while copying.
-Z Decompresses while extracting.

,estoring files:
Files are restored with `-x (extract) key option. When no file or directory name is specified,
it restores all files from the back up device. The following command restores the files just
backed up:
#tar xvfb /dev/rdsk/fo 18
x /home/sales/SQL/invoice - all.sql 1 tape blocks
x /home/sales/SQL/load2 - all.sql 10 tape blocks
Selective extraction is also possible by providing one or more directory or filenames:
tar xv6 tune1 song
Unlike cpio when files are extracted, the modification times of the files also remain
unchanged. This can be overridden by the `-m option to reflect the system time at the time
of extraction.
=isplaying the archi$e:
Like in cpio, the `-t key option simply displays the contents of the device without restoring
the files. When combined with the `-v option, they are displayed in a long format similar to
the listing:
#tar tvf /dev/rdsk/fo
rwxr _ xr _ x 203/50 472 Jun 4 09:35 1991 ./file1.sh
(ppending to the archi$e:
A file can be added to the archive with the `-u option. Since this is a copying operation, the
`-c option cant be used in combination with this option. The unequal thing is that an
archive can contain several versions of the same file:
#tar uf /dev/rdsk/fo ./func.sh
Net;ork Utilities) ftp, rlogin, telnet, arp.
1%1>%1 ftp:
Copying files between non-unix hosts. It is the file transfer protocol.
$ftp source1 #open ftp connection to source1
Name :
Password :
ftp>ls #directory listing of remote host
.
.
.
who.c
writer.c
ftp > get writer.c
ftp > !ls #obtain directory of local host
ftp > put who.c
ftp > quit #disconnect
Goodbye
$
1%1>%& =istributing processing:
Some hosts supply limited password less accounts with user IDs like `user so those
explorers can roam the network without causing any harm.
Three utilities for distributing access are:
1. rlogin : Which allows you to log into a remote Unix host.
2. rsh : Which allows you to execute a command on a remote Unix host, and
3. telnet : Which allows you to execute commands on any remote host that has
a telnet server.
Of these, `telnet is the most flexible, since there are other systems in addition to Unix that
support telnet servers.
rlogin ) ,e!ote logins:
To logon to the remote host, we use rlogin.
"ynta' : rlogin ec [-l useID] hostName
`rlogin attempts to log you into the remote host host-ame"If you dont supply a user ID by
using the `-l option, your local user ID is used during the login process.
If the remote host is not set as an equivalent of your local host in your $Home/.rhost file,
your are asked for your password on the remote host.
Once you are connected, your local shell goes to sleep the remote shell starts to execute.
When you are finished with the remote login shell, terminate it in the normal fashion(ctrl D)
and your local shell will then awaken.
There are a few special escape commands each is preceded by the escape character,
which is a tilde (~) by default, you may change this escape character by following the `-e
option with the preferred escape character.
-scape co!!ands:
SEQUENCE MEANING
~. Disconnect immediately from remote host.
~susp Suspend remote login session. Restart remote login using `fg.
~d susp Suspend input half of remote login session, but still echo output from
login session to your local terminal. Restart remote login using `fg.
-' : $rlogin user2 #remote login
Last login: Tue Dec 20 17:23:51 from Varun
user2 % date
Wed Dec 21 18:50:47 CDT 2005
user2 %
^
D #terminate the remote login shell
connection closed.
$- #back home again at Varun
Here, we have logged into remote host `user2 from local host `Varun.
"ynta' : ftp n [hostname]
'ftp( allows you to manipulate files and directories on your local host and a remote host.
1%1>%2 telnet ) ,e!ote connection:
'telnet( allows you to communicate with any remote host on the Internet that has a ` telnet
server.
"ynta' : telnet [host[port]]
telnet establishes a two way connection with a remote port. If you supply a host name, but
not a port specifier, you are automatically connected to a telnet server on the specified host,
which typically allows you to log into the remote machine. If you dont even supply a host
name, 'telnet( goes directly into command mode (like ftp).
To enter command mode after you have established a connection, press ctrl-] which is the
telnet escape sequence. This causes the command mode prompt to be displayed. The
following commands, among others are accepted:
COMMAND MEANING
Close Close current connection.
Open host[port] Connect to `host with optional port specifier.
Quit Exit telnet.
Z Suspend `telnet(.
! Print summary of `telnet( commands.
1. -' : $telnet #start telnet
telnet > ? #get help
commands may be abbreviated. Commands are:
close close current connection.
z suspend telnet.
quit exit telnet.
.
.
.
telnet > open user3 #get a login shell from user3
- - -
- - -
login: 12A4 #user ID
password : * * * *
.
.
.
user3 % date
Tue Dec 20 17:23:24 CDT 2005
user3 %
^
D
connection closed by foreign host.
2. -' : $telnet user3
login:
. . .
3. -' : $telnet user3 13 [port 13 is for time and day]
. . .
Tue Dec 20 17:26:32 2005
Connection closed by the foreign host.
Port 7 echoes everything that you type back to your terminal and is sometimes known
as `ping-port.
$telnet user3 7
. .
hi

hi


^
]
telnet >quit
connection closed
'telnet( accepts numeric internet address as well as symbolic names.
$telnet 129.110.43.128 7 #user3s numeric address
1%1>%> arp ) (ddress ,esolution #rotocol)
The arp command is used to manipulate system arp cache.
$arp options hostname
Options:
-d - deletes hostname
-a - displays entry of given host
-n - shows numerical address
In a networked system when a packet arrives at router machine then the IP address to
Ethernet address mapping is needed. This is achieved by arp protocol. Theses mappings are
stored in arp cache such that next time another packet arrives the same ip address then its
Ethernet or physical address is calculated by carrying out a lookup operation on the arp
cache. With arp command we can modify, view, delete the entries of this cache.

Potrebbero piacerti anche