0% found this document useful (0 votes)
7 views

Unix Unit 1 Part 2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Unix Unit 1 Part 2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

7

.· T h e F il e System
I
In this chapter, we begin our study of one of the two pilla
rs that supp ort UN IX- the file sys~cm.
UNIX looks at everything as a file and any UNIX syste
m has thou sand s of files. If you wntc l
program, you add one more file to the system. When you
compile it, you add some more. Files
grow rapidly, and if they are not organized properly, you'll
find it difficult to locate them. Just as an
office has separate file cabinets to group files of a similar
nature, UN IX also organizes its own files
in directories and expects you to do that as well. _. _ _
The file system in UNIX is one of its simple and conceptu
;lly clean features. It lets users a~ms
other files not belonging to them, but it also offers an adeq
uate security mechanism so ~utsiders
arc not able to tamper with a file's contents. In this chapter,
you'll learn to create directories! move
around within the system, and list filenames in these direc
tories'. We'll deal with file attnbutcs,
including the ones related to s~curity, in~ later chapter._
• •• ' :'
I • ---i
WHATYOUWILLLEARN ·-- ,~ --. •
• .. '.
• The initial categorization of files into three type's--0nlinar
y~ directory and device.
• The features of a UNIX filename. - • r ...... - . '. '.
• The hierarchical structure containing files and directorie
s, and the pare nt-c hild relationship
that exists between them.
.,
• The significance of the home directory and HOME variable.
• Navigate the file system with the cd and pwd commands
.
• Create and remove directories with mkdir and nndir.
• The significance of absolute and relative pathnames.
• U_se ls to list filenames in a directory in different formats.

TOPICS OF SPECIAL lNI'ERFST


• The significance of the important directories of the UNI
X file system from a functional point

• How It Works: Agraphic that shows how mkdir and mli
r affect a directory.
The File System •65-I
4.1 THE FILE
The file is a containe r for storing information. As a first approximation, we can treat it simply as a
sequence of characters. If you name a file foo and write three characters a, band c into it, then foo
will contain only the string abc and nothing else. Unlike the old DOS files, a UNIX file doesn't
contain the eof (end-of-file) mark. A file's size is not stored in the file, nor even its name. All file
attributes are kept in a separate area of the hard disk, not directly accessible to humans, but only to
the kernel.
UNIX treats directories and devices as files as well. A directory is simply a folder where you store
filenames and other directories. All physical devices like the hard disk, memory, CD-ROM , printer
and modem are treated as files. The shell is also a file, and so is the kernel. And ifyou are wonderin g
how UNIX treats the main memory in your system, it's a file too!
So we have already divided files into three categories:
•·Ordina ry file-Als o kn~wn as regular file. It contains only data as a stream of characters.
• Directory file-It's commonly said that a directory contains files and other directories, but
strictly speaking, it co~tains their names and a nu~ber associated with each name.
• Device file-All devices and peripherals are represented by files. To read or write a device, you
have to perform these operations on its associated file.
There are other types of files, but we'll stick to these three for the time being. The reason why we
make this distinction between file types is that the significance of a file's attributes often depends
on its type. Read permission for an ordinary file means something quite different from that for a
directory. Moreover, you can't directly put something into a directory file, and a device file isn't
really a stream of characters. While many commands work with all types of files, some don't. For a
proper understa nding of the file system you must understand the significance of the_se files.
4.1.1 Ordinary (Regular) File
An ordinary file or regular file is the most commou file type. All programs you write belong to
this typ_e. An ordinary file itself can be divided into two types:
. .
• Text file
• Binary file .
A text file contains only printable characters, and you can often view the contents and make sense
out ofthem. All C and Java program sources, shell and perl scripts are text files. A text file contains
lines ofcharacters where every line is terminated with the newline character, also known as linefeed
(LF). When you press [Enter} while inserting text, the LF character is appended to every line. You
won't sec ~is character normally, but there is a command (od) which can make it visible.

A binary file, on the other hand, contains both printable and unprintable characters that cover the
entire ASCII range (0 to 255). Most UNIX commands are binary files, and the object code and
executables that you produce by compiling C programs are also binary files. Picture, sound and
video files are binary files as well. Displaying such files with a simple cat command produces
unreadable output and may even disturb your terminal's settings.
Ii) UNIX: Concepts and Applications

4.1.2 Dir ect ory File


A dire ctor y contains no data, but keeps som
e details of the files and sub dire ~to ries _
The UN IX file system is organized with a num tha t it contaill\
ber of dire ctor ies and su_ bd1 rect one s,
also create them as and when you need. You and yo~ Qi
often nee d to do tha t to gr_oup a ~et of
to a specific application. Thi s allows two or files pertainin1
mor e files in sep ara te dire cto nes to have
, filename. , the sail'(
A directory file contains an entry for every file
and sub dire ctor y tha t it hou ses . If you
in a directory, there will be 20 entries in the have 20 filci
directory. Eac h ent ry has two com pon ent
s:
• The filename.
• A unique identification number for the file //
or dire ctor y (cal led the ino de num ber ).
Ifa directory bar contains an entry for a file
foo, we com mon ly (an d loo sely ) say tha
bar contains the file foo. Though we'll ofte t the directory
n be usin g the phr ase "co nta ins the file
"contains the filename", you must not inte " rather than
rpret the stat eme nt liter ally . A dire ctor
filename and not the file's contents. y contains th,

You can't write a 1irectory file, but you can


perform som e acti on tha t mak es the kern
directory. For instance, when you create or el write a
remove a file, the ker nel aut om atic ally
corresponding directory by adding or removin upd ates its
g the entr y (ino de num ber and file nam
with the file. e) associated

• Note: The name of a file can only be foun


d in its directory; the file itself doe sn't con tain
any of its attributes, like its size or access rights. its own name or

4.1.3 Device File


You'll also be printing files, installing softwar
e from CD -RO Ms or bac kin g up files to
these activities are performed by reading or writ tape. All of
ing the file rep rese ntin g the dev ice. For
when you restore files from tape, you read the instance,
file associated wit h the tape driv e. It is adva
to treat devices as files as some of the comman ntag eous
ds used to access an ord ina ry file also wor
device files. k with
Device filenames are generally found inside a
single directory stru ctur e, /dev . A dev ice
special; it's not really a stream of characters. file is indeed
In fact, it doesn't con tain any thin g at all.
learn that every file has some attributes that You'll soon
arc not stored in the file but else whe re on
operation ofa device is entirely governed by the disk. The
attributes ofit s asso ciat ed file. Th e ker nel
a device from its a~b ute s and then uses them identifies
to operate the device. I' ' I ·
Now that you understand the three types of
files, you sho uldn 't feel baff ied by sub seq
~e word in the book. The term "file" will ofte uen t use of
1 n be used in this boo k to refe r to any of thes
' though it will mostly be used
to mean an ordinary file. The real mea nin e types,
evident from its context. g of the term sho uld be
The File System --II
lr=-=-1_67

4.2 WHAT'S IN A (FILE)NAME?


On most UNIX systems today, a filename can consist of up to 255 characters, though this figure is
normally not reached. Files may or may not have extensions, and can consist of practically any
ASCII character except the/ and the NULL character (ASCII value 0). You arc permitted to use
control characters or other unprintable characters in a filename. The following are valid filenames
in UNIX: •
.last_time list. "V"B"D-++bcd -{}[] @#$%*abed a.b.c.d.e
The third filename contains three control characters ([Ctrl-v] being the first). These characters
should definitely be avoided in framing filenames. Moreover, since the UNIX system has a special
treatment for characters like$,·,?,*, & among others, it is recommended that only the following
characters be used in filenames:
• Alphabetic characters and numerals.
• The period(.), hyphen(-) and underscore LJ.
UNIX imposes no rules for framing filename extensions. A shell script doesn't need to have the
. sh extension, even though it helps in identification. In all cases, it's the application that imposes
the restriction. Thus the C compiler expects C program filenames to end with . c, Oracle requires
SQL scripts to have the . sq l extension, and so forth. _DOS/Windows users must also keep these
two points in mind:
• A file can have as many dots embedded in its name; a.b.c .d.e is a perfectly valid filename. A
filename can also begin with a dot or end with one.
• UNIX is sensitive to case; chapOl, ChapOl and CHAPOl are three different filenames, and it's
possible for them to coexist in the same directory.

Caution: Never use a - at the beginning of a filename. You'll have a tough time getting rid of it!
A command that uses a filename- as argument often treats it as an option and reports errors. For
instance, if you have a file named -z, cat -z won't display the file but interpret it as an invalid option.
11

4.3 THE PARENT-CHILD RELATIONSHIP


~1 files in UNIX arc "related" to one anothe;. The file system in UNIX is a collection of all of
these related files (ordinary, directory and device files) organized in a hierarchical (an inverted
tree) structure. This system has also been adopted by DOS and Windows, and is visually represented
in fig. 4.1.
The implicit feature of every UNIX file system is that there is a top, which serves as the reference
point for all files. This top is called root and is represented by a/ (frontslash). root is actually a
direaory. It is conceptually different from the user-id root used by the system administrator to log
in. In this text, we'll be using both the name "root" and the symbol/ to represent the root directory.
168 i UNIX: Concepts and Applications
----
root (/)

bin lib shin stand tmp usr var

cat unix bin includ e sbin

f0ql8dt login.sql progs safe

Fig. 4.1 The UNIX File System Tree


The root directory (/) has a number of subdirectories under it. These subdirectories
in turn ha,•c
more subdirectories and other files undeI them. For instance, bin and us r are two directo
ries direcdy
under/, while a second bin and kumar are subdirectories under usr.
Every file, apart from root, mu;t have a parent, and it should be possible to tr~ce
the ultimate
parentage of a file to root. Thus, the home directory is the parent of kumar, while / is the
parent of
home, and the grandparent of kumar. If you create a file 1ogi n. sql under the kumar director
y, then
kumar will be the parent of this file.
It's also obvious that, in these parent-child relationships, the parent is always a director
y. home
and kumar are both directories as they are both parents ofat least one file or directory.
1ogi n. sql is
simply an ordinary file; it can't have any directory under it.

4.4 THE HOME VARIABLE: THE HOME DIRECTORY


When you log on to the system, UNIX automatically places you in a directo ry
called the
home directory. It is created by the system when a user account is opened. If you log
in using the
login name kumar, you'll land up in a directory that could have the pathna me /home/k
umar (or
something else). You can change your home directory when you like, but you can
also effect a
quick return to it, as you'll sec soon ..
The File System

The shell variabl e HOME knows your home directo ry:


$ echo $HOME
/home/ kumar First/ represents the root directory
directo ry names
What you see above is an absolu te pathna me, which is simply a sequen ce of
n with referen ce to the top, i.e.,
separat ed by slashes . An absolut e pathna me shows a file's locatio
slash is a synony m
root. These slashes act as delimit ers to file and directo ry names, except that thefirst
for root. The directo ry kumar is placed two levels below root.
/too. Further ,
It's often conven ient to refer to a file foo located in your home directo ry as $HOME
/too is the same as
most shells (except Bourne ) also use the - symbol for this purpos e. So, $HOME
any user's home
-/foo in these shells. The - symbol is a little tricky to use becaus e it can refer co
home director y, then kumar
directo ry and not just your own. If user sharma has the file too in his
can access it as -sharm a/too. The princip le is this:
d by a stn·ng
A tilde followe d by/ (like -/too) refers to one's own home directory, bttt when followe
( -shann a) refers to the home directory ofthat user represented by the string.
opening a user
Note: The home directory is determi ned by the system adminis trator at the time of
, home directories are
accoun t. Its pathna me is stored in the file /etc/pa sswd. On many UNIX systems
. Even if you
maintai ned under /home, but your home directory could be different (say, in /export /home)
the cd comma nd to effect a quick return to it, as you ·u
have moved away from your ~home", you can use
see soon.

4.5 pwd: CHE~ KING YOUR CURRENT DIRECTORY


ry of the file
UNIX encour ages you to believe that, like a file, a user is placed in a specific directo
point oftime,
system on logging in. You can move around from one directo ry to another , but at any
t directo ry.
you are located in only one director y. This directo ry is known as your curren
(print workin g
At any time, you should be able to know what your current directo ry is. The pwd
directo ry) comma nd tells you that:
$ pwd
/home/k umar
cd comma nd,
Like HOME, IMf display s the absolut e pathnam e. As you navigat e the file system with the
you'll be using pwd to know your current directory.
ing on the
Note: It's custom ary to refer to a file too located in the home directory as $HOME/too. Depend
is shell-de pendent but the
shell you use, it may be possible to even access too as -/foo. One form
other Isn't, but both naming conven tions are followed in this text.

4.6 cd: CHAN GING THE CURRENT DIRECTORY


used with
You can move around in the file system by using the cd (change directory) comma nd. When
instanc e, progs:
an argume nt, it changes the current directory to the directory specified as argume nt, for
J

( ?P-1 UNIX: Concepts and Applications

s pwd
/home/kumar
$ cd progs progs must be in current directory
$ pwd
/home/kumar/progs
Though pwd displays the absolute pathname, cd doesn't need to use one. The command cd Pl'lt
here means this: "Change your subdirectory to progs under the current directory." Using a path
causes no harm either; use cd /home/kumar/progs for the same effect.
When you need to switch to the /bin directory where most of the commonly used UNIX comma~
are kept, you should use the absolute pathname:
$ pwd
/home/kumar/progs
$ cd /bin Absolute pathname required here becaua
$ pwd bin' isn't in currmt directory
/bin '
I .
We can also navigate to /bin (or any directory) using a different type of pathname; we are comini
to that shortly. .
cd can also be used without any arguments:
s pwd
/home/kumar/progs
$ cd cd used without argumenll
$ pwd reverts to the home directory
/home/kumar
I
Attention, DOS users! This command invoked without an argument doesn't indicate the ~~rrcnl
directory. It simply switches to the home directory, i.e., the directory where the user ongmally
logged into. Therefore, ifyou wander around in the file system, you can force an immediate return
to your home directory by simply using cd:
$ cd /home/sharma
$ pwd
/home/shanna
$ cd Returns to home directory
$ pwd
/home/kumar
The cd command can sometimes fail if you don't have proper permissions to access the directori
This doesn't normally happen unless you deliberately tamper with the permissions ofthe directo~
The technique of doing that is described in Section 6.5. .

Note: Unlike in DOS, when cd is invoked without arguments, it simply reverts to its home directory. It
doesn't show you the current directory!
The File System t71 I
4.7 mkdir: MAKING DIRECTORIES
'
Directories are created with the 111kdir (make directory) command. The command is followed by
names of the directories to be created. A directory patch is created under the current directory like
this:
mkdir patch
You can create a number of subdirectories with one 11kdir command:
mkdir patch dbs doc Three directories created

So far, simple enough, but the UNIX system goes further and lets you create directory trees with
just one invocation of the command. For instance, the following command creates a directory tree:
mkdir pis pis/progs pis/data Creates /he directory tree

This creates three subdirector ies-pis and two subdirectories under pis. The order of specifying
th1; arguments is important; you obviously can't create a subdirectory before creation of its parent
directory. For instance:, you can't enter
$ mkdir pis/data pis/progs pis ..
mkdir: Failed to make directory •pis/data"; -'No such file or directory
mkdir: Failed to make directory "pis/progs" ; No such file or directory
Note that even though the system failed to create: the two subdirectories, progs and data, it has still
created the: pis directory.
Sometimes, the system refuses to create: a directory:
$ test
mkdir: Failed to make directory •test"; Pennission denied
This can happen due: to these: reasons:
• The: directory test may already exist.
• There may be an ordinary file by that name: in the current directory.
• The permissions set for the current directory don't permit the creation of files and directories
by the user. You'll most certainly get this message if you try to create a directory in /bin, /etc
or any other directory that houses the UNIX system's files.
We'll take up file and directory permissions in Chapter 6 featuring file attributes.

4.8 nndi r: REMOVING DIRECTORIES


The l'lldir (remove directory) command removes directories. You simply have to do this to remove
the directory pis:
nndir pis Directory must be empty
l
UNIX: Concepts and Applications

Like mkdir, nndir can also delete more than one directory in one shot. For instance, _the t~,.
directories and subdirectories that were just created with mkdi r ca~ be removed by ustng Ill~
with a reversed set of arguments: . I
rmdir pis/data pis/progs pis

Note that when you delete a directory and its subdirectories, a ~everse logic has to be applied.
following directory sequence used by mkdi r is invalid in ~di r:
$ nndir pis pis/progs pis/data
rmdi r: di rectory II pis 11 : Di rectory not empty
Have you observed one thing from the error message? nndi r has silently deleted the lowest ICl't
subdirectories progs and data. This error message leads to two important rules that you shou~
remember when deleting directories:
• You can't delete a directory with rmdirunless it is empty. In this case, the pis directory couldn't
be removed because of the existence of the subdirectories, progs and data, under it.
• You can't remove a subdirectory unless you a~e placed in a directory which is hierarchicalli
above the one you have chosen to remove.
The first rule follows logically from the example above, but the highlight on nndi r has significanct
that will be explained later. (A directory can also be removed without using rmdi r.) To illustrate tht
second cardinal rule, try removing the progs directory by executing the command from the same
directory itself: •
$ cd progs
$ pwd
/home/kumar/pis/progs
$ nndir /home/kumar/pis/progs
11
Trying to remove the cun-ent directory
rmdir: directory /home/kumar/pis/progs": Directory does not exist
To remove this directory, you must position yourself in the directory above progs, i.e., pis, and
then remove it from there:
$ cd /home/kumar/pis
$ pwd
/home/kumar/pis
$ nndfr progs
The mkdf rand rmdi r commands work only in directories owned by the user. Generally, a user is the
owner of her home directory, and she can create and remove subdirectories (as well as regular files)
in this directory or in any subdirectories created by her. However, she normally. won't be able to
create or remove files and directories in other users' directories. The concept of ownership wiJI be
discussed in Section 6.3. ·

Note: A subdirectoiy can't be removed with rmdir unless it's empty, and one is positioned in its parent
directoiy or above it. But we can remove a directoiy without using rmdf r also (discussed later).
r73I
The File System --1

Pii#W u:,,::z;; tfo:'F1ie!'!~~ o::~~;,:~ ar! creaie!:~nd ~e':!v~;,


1 1

h: ii ta ms i: I r :r z rx ??ittnsr: rrrw r x wrnr:a nv»+ ·J


As mentioned in Section 4.1.2, a ftle (ordinary or directory) is associated with a name and a number,
called the inode number. When a directory is created, an entry comprising these two parameters is
made in the file's parent directory. The entry is removed when the directory is removed. The same holds
good for ordinary files also. Figure 4.2 highlights the effect of mkdi r and nndi r when creating and
removing the subdirectory progs in /home/kumar.

Filename Inode Filename Inode Filename Inode


Number Number Number
. 386444 mkdir progs . 386444 nndir progs . 386444
.. 417585 .. 417585 .. 417585
foo -499770 foo 499770 foo 499770
progs 162112

Fig. 4.2 Directory Entry after mkdi r and nndi r


Later in this chapter, we'll discuss the significance of the entries, . and . : , that you'll find in every
directory. In this chapter and Chapters 5 and 11, we'll be progressively monitoring this directory for
changes that are caused by some of the file-handling commands.

4.9 ABSOLUTE PATHNAMES


Many UNIX commands use file and directory names as arguments, which are presumed to exist
in the current directory. For instance, the command
cat login.sql
will work only if the file 1ogi n. sq 1 exists in your current directory. However, if you are placed in
/usr and want to access login.sql in /home/kumar, you can't obviously use the above command,
but rather the pathname of the file:
cat /home/kumar/lo gin.sql
& stated before, if the first character of a pathname is/, the file's location must be determined with
respect to root (the first/). Such a pathname, as the one above, is called an absolute pathname.
When you have more than one/ in a pathname, for each such/, you have to descend one level in
the file system. Thus, kumar is one level below home, and two levels below root.
When you specify a file by using frontslashes to demarcate the various levels, you have a mechanism
ofidentifying a file uniquely. No two files in a UNIX system can have identical absolute pathnames.
You can have two files with the same name, but in different directories; their pathnames will also
be different. Thus, the file /home/kumar /progs/c2f. pl can coexist 'with the file
/home/kumar/sa fe/c2f.pl.
l
-
I14 J UNIX: Concepts and Applications

4.9.1 Using the Absolute Pathname for a Command


More often than not, a UNIX command runs by executing its disk file. When you specify
command, the system has to locate the file date from a list of directories specified in~
variable, and then execute it. However, if you know the location of a particular comma~\
precede its name with the complete path. Since date resides in /bin (or /usr/bin), youc.iqt
the absolute pathname: •
S /bin/date
Thu Sep 1 09:30:49 1ST 2005
Nobody runs the date command like that. For any command that resides in the directories
in the PATH variable, you don't need to use the absolute pathname. This PATH, you'll rec.illg
invariably has the directories /bin and /usr/bi n in its list.
Ifyou execute programs residing in some other directory that isn't in PATH, the absolute pi
then needs to be specified. For example, to execute the program 1ess residing in /usr/lOQJ
you need to enter the absolute pathname: '
/usr/local/bin/less
If you are frequently accessing programs in a certain directory, it's better to include the d'
itself in PATH. The technique of doing that is shown in Section 10.3.

4.10 RELATIVE PATHNAMES


You would have noted that in a previous example (4.8), we didn't use an absolute pathn1t1
move to the directory progs. Nor did we use one as an argument to cat (4.9):
cd progs
cat login.sql
Here, both progs and login.sql are presumed to exist in the current directory. Now, ifprogs~
contains a directory scripts under it, you still won't need an absolute pathname to chin~
that directory:
cd progs/scripts progs is in cu"ent directory
Herc we have a pathname that has a/, but it is not an absolute pathname because it doesn't
with a/. In these three examples, we used a rudimentary form of relative pathnames th~..
they are generally not labeled as such. Relative pathnames, in the sense they are knowo,~
discussed next.

4.10.1 Using . and .. in Relative Pathnames


I~ a preceding example (4.8), you changed your di rectory from /home/kuma r/pf s/ progs to its plllf
duectory (/home/kumar/pis) by using cd with an absolute pathname:
cd /home/kumar/pis
The File System

Navigatio n often becomes easier b-y using a common ancestor (here, /home) as refcrePcc. UNIX
offers a shortcut -the relative pathnam e-that uses either the current or par~nt directory as
reference , and specifies the path relative to it. A relative pathname uses one ofthese cryptic symbols:
• . (a single dot}-Th is represents the current directory.
• .. (two dots)-Th is represents the parent directory.
We'll now use the .. to frame relative pathnam es. Assumin g that you arc placed in
/home/ku mar/prog s/data/tex t, you can use .. as an argument to cd to move to the parent directory,
/home/ku mar/progs /data:
$ pwd
/home/ku mar/prog s/data/tex t
$ cd . . Moves one level up
$ pwd
/home/ku mar/progs /data
This method is compact and more useful when ascending the hierarchy. The command cd
translates to this: "Change your directory to the parent of the current directory." You can combine
any number of such sets of .. separated by /s. However, when a / is used with .. it acquires a
different meaning; instead of moving down a level, it moves one level itp. For instance, to move to
/home, you can always use cd /hOllle. Alternatively, you can also use a relative pathname :
$ pwd
/home/kum ar/pis
$ cd .. /.. Moves two levels up
$ pwd
/home
Now let's turn to the solitary dot that refers to the current directory. Any command which uses the
current directory as argument can also work with a single dot. This means that the cp command
(5.2) which also uses a directory as the last argument can be used with a dot:
cp •• /sharma/ .profile . Afilenam ecan begin with a dot

This copies the file .profile to the current directory (.). Note that you didn't have to specify the
filename of the copy; it's the same as the original one. This dot is also implicitly included whenever
we use a filename as argument , rather than a pathname . For instance, cd progs is the same as
cd ./progs.

Note: Absolute pathnames can get very long if you are located a number of "generations" away from
root. However, whether you should use one depends solely on the number of keystrokes required when
compared to a relative pathname. In every case here, the relative pathname required fewer key depressions.
Depending on where you are currently placed, an absolute pathname can be faster to type.

4.11 1s: LISTING DIRECTORY CONTENTS


You have already used the ls command (1.4.9) to obtain a list of all filenames in the current directory.
L:t's execute it again:
t

J
1
lz!J f
UNIX: Concepts and PPlications

$ ls
08 packets.html Numer als first
TDC.sh Uppercase next
calendar Then lowercase
cptodos.sh
dept.1st
emp. l st
helpdir
progs
usdsk06x
usdsk07x
usdsk08x
What you see here is a complete: list of filenames in the: curren t direct ory arr~ngcd
in ASQ
collating sequence (numbers first, uppercase and then lowercase:), with one filenam
e in cad.
line. It includes directories also, and ifyou arc using Linux, you would probab ly sec the
dircctoric'
and ordinary filcs•in different colors.
µN~ _If your Linux_ system ~·t~the se.~ ~~ ~·sure·that ·you
Joggingm: . . ·:..!. . ,.. • • . ,.. . ~... , •
create 'ihis alias~I
!
,

alias l·s•'ls --color-:tty' ·~·--· :::·/ .--;,·•. ~·' _·.. :.- • \ ,· •• '. • . ,; "' .I
~ar e ~ m__~;}~ ;~~. ·~~; :~-~ aren otsu ~ ~-~e B o
~
Directories often contain many files, and you may simply be interc:stc:d in only knowing
whethm
particular file is available. In that case, just use 1s with the: filename:
$ ls calendar
calendar
and ifperl isn't availa!j,c, thc_systcm clearly says so:
$ Is perl
perl: No such file or directory
1scan also be used with multiple filenames, and has options that list most of the: file
attributes. In
the following sections, you'll sec some of these options.

4.11.11s Options
Is _has a large number of options (Table 4.I), but in this ·chapter, we'll presen t a handful of
them.
The other options will be taken up in later chapters. The section numbers arc appropriately
indicated
in the table.
Output in Multiple Columns (-x) When you have several fil~s, it's better to display the
filenames
in multiple columns. Modern versions ofl s do that by default (i.e., when used withou
t options),
but ifthat doesn't happen on your system, use the -x option to produc~ _a J_DUlticolumn
ar output:
s 1s -x
The File System r77
L I
08 packets.htm l T0C.sh calendar cptodos.sh
dept.1st emp.lst helpdir progs
usdsk06x usdsk07x usdsk08x ux2nd06
If your system needs to use the -x option to display multicolumn ar output, you can later customize
the command to display in this format by default (10.4).
Identifying Directories and Executables (-F) The output of 1s that you have seen so far merely
showed the filenames. You didn't know how many of them, if any, were directory files. To identify
directories and executable files, the -F option should be used. Combining this option with -x produces
a rnulticolumn ar output as well:
$ ls -Fx
08 packets.htm l TOC.sh* calendar* cptodos.sh*
dept.1st emp. l st helpdir/ progs/
usdsk06x usdsk07x usdsk08x ux2nd06
Note the use of two symbols, • and /, as type indicators. The * indicates that the file contains
executable code and the / refers to a directory. You can now identify the two subdirectories in the
current directory-h el pdi r and progs. •
Showing Hidden Files Al.so (-a) ls doesn't normally show all files in a directory. There are
cenain hidden files (filenames beginning with a dot), often found in the home directory, that
normally don't show up ~n the listing. The -a option (all) lists all hidden files as well:
$ ls -axF
./ .. / .exrc .kshrc
.profile . rhos ts . sh hi story .xdtsupCheck
.xfnitrc 08_packet~.html* roc:sh* calendar*

The file . profile contains a set of instructions that are performed when a user logs in. It is
conceptually similar to AUT0EXEC. BAT of DOS, and you'll know more about it later. The other file,
.exrc, contains a sequence ofstartup instructions for the vi editor. To display these hidden filenames,
you can either use the -a option or specify the filenames in the command line. •
The first two files (. and .. ) are special directories. Recall that we used the same symbols in relative
pathnames to represent the current and parent directories (4.10.1). These symbols have the same
meaning here. Whenever you create a subdirectory, these "invisible" .directories are created
automatically by the kernel. You can't remove them, nor can you write into them. They help in
holding the file system together. •

Note: All filenames beginning with a dot are displayed only when 1s is used with the -a option. The
directory . represents the current directory and .. signifies the parent directory. I

Listing Directory Contents, . l!1 ·t9e las·t example, you specifi,ed some ordinary filenames to 1s to
have a selective listing. However, the situation will be quite different ifyou specify tl).e two directory
names, hel pdf r and progs, inslead:,
, I!~1 UNIX: Concepts and Applications
, $ ls -x helpdir progs
helpdir:
fonns.obd graphics.obd reports. obd
progs:
array .pl cent2fah.pl n2words.pl name.pl
This time the contents of the directories are listed, consisting of the Oracle documentation in tht
he1pdi r directory and a number of perl program files in progs. Note that ls, when used with
directory names as arguments, doesn't simply show their names as it does with ordinary files.
Recursive Listing (-R) The -R (recursive) option lists all files and subdirectories in a directory
tree. Similar to the DIR /S command of DOS, this traversal of the directory tree is done recursively
until there are no subdirectories left:
$ ls -xR .
0B_packets.html T0C.sh calendar cptodos.sh
dept.1st emp.lst helpdir progs
usdsk06x usdsk07x usdsk0Bx _ ux2nd06
./helpdir:
forms.hlp graphics. hl p reports.hlp
./progs:
array.pl cent2fah.pl n2words.pl name.pl
The list shows the filenames in three sections-the ones under the home directory and those
under the subdirectories he1pdi rand progs. Note the subdirectory naming conventions followed;
./helpd ir indicates that-helpdir is a subdirectory under. (the current directory). Since
/home/kumar happens to be the current directory, the absolute pathname of this file expands to
/home/kumar/helpdir.

Table 4.1 Options to ls •


Option Description
-x Multicolumnar output
-F Marks executables with*, directories with/ and symbolic links with@
-a Shows all filenames beginning with a dot including . and ..
-R Recursive list _
-r Sorts filenames in reverse order (ASCII collating sequence by default)
-1 Long listing in ASCII collating sequence showing seven attributes ofa file (6.1)
-ddimame Lists only dimame if Jimame is a directory (6.2)
-t Sons filenames by last modification time (11.6)
-lt Sorts listing by last modificatio~ time (11.6)
-u Sorts filenames by last access time (11.6) .
-lu Sorts by ASCII collating sequence but listing shows last access time (11 .6)
-lut As above but sorted by last access time (11.6)- .,
-f Displays inodc number (11.1)
The File System 1
4.12 THE UNIX FILE SYSTEM
Let's conclude
We have learned to use the basic command set for handling files and directories.
. This structu re
this chapte r by taking a cursor y look at the structu re of the UNIX file system
its SVR4 release.
has been chang ing consta ntly over the years until AT&T propos ed one in
has been adopte d
Thoug h vendo r implem entatio ns vary in detail, broadl y the SVR4 structu re
by most vendo rs.
file system. In real
Refer to Fig. 4.1 which shows a heavily trimmed structure of a standard UNIX
but for_ our initial
life, the root directory has many more subdirectories under it than shown,
strative point of
comprehension, we'll stick to the ones presented below. It helps, from the admini
group contains
view at least, to view the entire file system as comprising two groups offiles. The first
the files that_ are made avail~blc during system installation:
commands
• /bin and /us r /bin-T hese arc the directories where all the commonly used UNIX
shows these
(binaries, hence the name bin) arc found. Note that the PATH variable always
directories in its list.
administrator
• / sbi n and /usr/sbi n--If there's a command that you can't execute but the system
execute most
can, then it would probably be in one of these directories. You won't be able to
PATH shows
(some, you can) commands in these directories. Only the system administrator's
these directories.
change a very
• /etc-T his directory contains the configuration files of the system. You can
login name
import ant aspect of system functioning by editing a text file in this directory. Your
and password are stored in files /etc/pa sswd and /etc/shadow.
on disk. There
• /dev- This directory contains all device files. These files don't occupy space
could be more subdirectories like pts, dsk and rdsk in this directory.
C programs
• /lib and /usr/1 ib--Co ntain all library files in binary form. You'll need to link your
with files in these directories.
The statem ent
• /usr/in clude- --Con tains the standa rd header files used by C programs.
ry.
#inclu de <stdio . h> used in most C programs refers to the file stdio. h in this directo
e subdirectories
• /usr/s hare/m an-Th is is where the man pages arc stored. There are separat
e, the man page
here (like man 1, man2, ctc.).that contain the pages for each section. For instanc
. l of the
ofl scan be found in /usr/share/man/manl, where the 1 in manl represents Section
(like smanl,
UNIX manual. These subdirectories may have different names on your system
srnan2, etc. in Solaris). ,
s are added
Over time, the contents of these rfircctorics would change as more software and utilitie
receive mail and
to the system. Users also work with their own files; they write programs, send and
also create temporary files. These files are available in the second group shown below:
files are wiped
• /tmp- Thc directories where users are allowed to create temporary files. These
away regularly by the system.
!', • /var-T he variable part ofthe file system. Contai ns all your print jobs
and your outgoing and
' : • ·\·ncom1
' . 11
ng mail.' I

I
I
,,. •·\
Han dlin g Ord inar y File s
The last chapter examined the tools that handle directories. But users actually do most of their work
with ordinary (or regular) files, and it's natural that the UNIX system should feature a host of
commands to handle them. Although all of these commands use filenames as arguments, they were
not designed only to read files. In fact, many of them don't need to read a file at all. However, to
understand their basic functionality, we'll use them with filenames in this chapter.
We'll first consider the common file-handlin g commands that the DOS environmen t also offers,
except that the UNIX variety has more features. We'll also discuss those commands that show
differences between two files and convert files between DOS and UNIX formats. Finally, we'll
examine the important compression utilities with which we handle documents and software found
on the Internet. As we progressively discover the shell's features in later chapters, we'll learn to use
the same commands in other ways.
WHAT You WILL LEARN
1
• View text files with cat and more (or less)
• Use cat to create a file.
• The essential file functions--c opy with cp, remove with rm and rename with 111v.
• Print a file with lp (lpr in Linux).
• Classify files with file.
• Count the number oflines, words and characters with we.
• Display the ASCII octal value of text with od.
• Compare two files with~. COIII and diff.
• Compress and decompress files with gztp and gunzip.
• Create an archive comprising multiple files with tar.
• Perform both functions (compressin g and archiving) with zip and unzip.

TOPICS OF SPECIAL 1NrEREsT


• A discussion on the issues related to file compression and archival.
• Convert between UNIX and DOS files with unix2dos and dos2untx.
• How It Works: A graphic showing how a directory is affected by cp, mv and rm.
Handling Ordinary Files ~ 3 ·,

5.1 cat: DISPLAYING AND CREATING FILES


cat is one of the most well-known commands of the UNIX system. It is mainly used to display the
contents of a small file on the terminal:
$ cat dept.1st
Oljaccountsj6213
02jprogsj5423
03 marketingj6521
04 personnell2365
05 productionj9876
06 salesjl006
cat, like several other UNIX commands, also accepts more than one filename as arguments:
cat chapOI chap02
The contents of the second file are shown immediately after the first file without any header
information. In other words, cat concatenates the two files-hence its name. • •

5.1.1 cat Options (-v and -n)


There are two cat options that you may find useful, though POSIX doesn't require cat to support
either one. '
Displaying Nonprinting Characters (-v) cat is normally used for displaying text files only.
Executables, when seen with cat, simply display junk. Ifyou have non printing ASCII characters in
your input, you can use cat with the -v option to display these characters.
Numbering Lines (-n) The -n option n'umbers lines. C compilers indicate the line number where
errors are detected, and this numbering facility often helps a programmer in debugging programs.
But then your vi editor can show line numbers too, and if your version of ca~ doesn't support -n,
you can use the pr (12.2) command to do the same job.

5.1.2 Using cat to Create a File


cat is also useful for creating a file. Though the significance of the following sequence can be
appreciated only after reading Section 8.5.2, you should now know how to create small files. Enter
the command cat, followed by the> (the right chevron) character and the filename (for example, foo):
S cat > foo
A> s,Ylllbol following the c011aand means that the
output goes to the filename following it. cat used
1n thts way represents a rudimentary editor.
{Ctrl-d]
$ Prompt returns
When the command line is terminated with [Enter}, the prompt vanishes. cat now waits to take
input from the user. Enter the three lines, each followed by [Enter}. Finally press {Ctrl-d} to signify
the end ~finput to the system. This is the eof character used by UNIX systems and is shown in the
184 j ,UNIX: Concepts and Applications
stty output (3.13). When this character is entered, the system understands that no further text input
will be made. The file is written and the prompt returned. To verify this, simply"cat" this file:
$ cat too
A> symbol following the cornnand means that the
output goes to the filename following it. cat used
in this way represents a rudimentary editor.

Note: The {Ctrl-d] character is used to terminate input not only with cat, but with all commands that
accept input from the keyboard. ' I
cat is a versatile command. It can be used to create, display, concatenate and append to files. More
importantl)I it doesn't restrict itselfto handling files only; it also acts on a stream. You can supply the
input to cat not only by specifying a filename, but also from the output of another command. You'll
learn about all this in Chapter 8.

5.2 cp: COPYING A FILE


The cp (copy) command copies a file or a group of files. It creates an exact image of the file on disk
with a different name. The syntax requires at least two filenames to be specified in the command
line. When both are ordinary files, the first is copied to the second:
cp chapOl unitl
If the destination file (uni tl} doesn't exist, it will first be created before copying takes place. If not,
it will simply be overwritten without any warning from the system. So be careful when you choose
your destination filename. Just check with the 1s command whether or not the file exists.
Ifthere is only one file to be copied, the destination can be either an ordinary or directory. You then
have the option of choosing your destination filename. The following example shows two ways of
copying a file to the progs directory:
cp chapOl progs/unitl chapOl copied to, uni t1 under progs
cp chapOl progs chapOl retains its name under progs
cpis often wed with the shorthand notation, . (dot), to signify the current directory_as the destination.
For instance, to copy the file .profile from /home/shanna to your current directory, you can use
either ofthe two commands:
cp /home/shanna/,profile .profile Destination is afile •
cp /home/shanna/.profile . Destination is the current directory
Obvious}~ the second one is preferable because it requires fewer keystrokes.
cp can also be used to copy more than one file with a single invocation of the command. In that
case, the last filename must be a directory. For instance, to copy the files chapOl, chap02 and chap03
to the progs directory, you have to use cp like this: •
cp chapOl chap02 chap03 progs
H~ndling Ordin ary Files El
y resident in progs, they will be
The files r~tain their original names in progs. Ifthese files are alread
tory must exist because cp won' t
overwritten. For the above comm and to work, the progs direc
create it.
frame a pattern for matc hing more
You have alrea dy seen (5.3) how the UNIX system uses the* to
nt directory having the comm on
than one filename. If there were only three filenames in the curre
a suffix to chap:
string chap, you can compress the above sequence using the* as
cp chap* progs Copies allfiles beginning with chap

We'll conti nue to use the* as a short hand for multiple filena
mes. Ther e are other mctacharacters
too, and they are discussed in complete detail in Section 8.3.

Note: In the previous example, c~ doesn't look for a file name


d chap*. Before it runs, the shell expands
chap* to regenerate the command line arguments for cp to use.

Caution: cp overwrites without warning the destination file if


it exists! Run 1s before you use cp unless
be overwritten.
you are sure that the destination file doesn't exist or deserves to

5.2.1 cp Opti ons I


the
Intera ctive Copy ing (-i) The -i (interactive) option warns the user before overwriting
destin ation file. If uni tl exists, cp prompts for a response:
$ cp -1 chapOl unitl
cp: overwrite unit! (yes/no)? y
it uncopied.
Ay at this prom pt overwrites the file, any other response leaves
Copying Directory StnlClures (-R) Many UNIX commands are capable of recur sive behavior.
ine all files in its subdirectories.
This mean s that the comm and can descend a directory and exam
structure, say, progs to newprogs:
The cp -R comm and behaves recurvely to copy an entire directory
cp -R progs newprogs newprogs must not exi"st
also exists as a directory. If newprog~
Atten tion I How cp behaves here depends on whether newprogs
ies. But if newprogs exists, progs
doesn 't exist, cp creates it along with the associated subdirector
comm and run twice in succession
becomes a subdirectory unde r newprogs. This means that the
will produ ce different results! •

if it's read-protected or the


Caution: Sometimes, It's not possible to copy a file. This can happenssed in Section 6.4.
ation file or directory Is write-protected. File permissions are discu
destin

5.3 rm: DELETING FILE~


\I I
operates silently and should be
The I'll (remove) comm and deletes one or more files. It normally
used with caution. The following comm and deletes three files:
I.,"
,' I
\ . (
l

r~ UNIX: Concepts and Applications

rm chapOl chapp2 chap03 rm chap* could be dangerous to use/


A file once deleted can't be recovered. rm won't normally remove a directory, but it can remove fila
from one. You can remove two chapters from the progs directory without having to "cd" to it:
rm progs/chapOl progs/chap02 Or rm progs/chap0[12]
You may sometimes need to delete all files in a directory as part ofa cleanup operation. The*, when
used by itsel~ represents all files, and you can then use rm like this:
$ rm * All files gone/
$
DOS users, beware! When you delete files in this fashion, the system won't prompt you with the
message All files in directory will be deleted! before removing the files! The$ prompt will
return silently; the work has been done. The * used here is equivalent to *. * used in DOS.

Note: Whether or not you are able to remove a file depends, not on the file's permissions, but on the
Permissions you have for the directory. Directory permissions are taken up in Section 6.6.

5.3.1 m Options
Interactive Deletion (-i) Like in cp, the -i (interactive) option makes the command ask the user
for confirmation before removing each file:
$ rm -1 chapOl chap02 chap03
rm: remove chapOl (yes/no)? ?y
rm: remove chap02 (yes/no)? ?n
nn: remove chap03 (yes/no)? [Enter} tNo response-file not deleted
Ay removes the file, a~y other response leaves the file undeleted.
Recursive Deletion (-ror -R) With the -r (or -R) option, ra performs a tree walk-a thorough
recursive search for all subdirectories and files within these subdirectories. At each stage, it deletes
everything it finds. I'll won't normally remove directon·es, but·• used with this option, it will.
Therefore, when you issue the command
nn -r * Behaves partiaily like rmd f r
you'll delete all files in the current dir~ctory and all its subdirectories. Ifyou don't have a backup,
then these files will be lost forever. .--/'
Forcing Removal (-f) -------
I'll prompts forremoval ifa file is ~rite-protected. The -f option overrides
this minor protection and forces removal When you combine it with the -r option, it could be the
most risky thing to do:
nn -rf * Deletes everything in the a'"ent directory and below
. ,,I • \
I

Handling Ordinary Files ·!BJ


• I
nn *. Be doubly sure before you
Caution: Make sure you are doing the right thing before you use
current directory. The second one
use m -rf *. The first command removes only ordinary files in the
user) invokes m -rf * in the
removes everything-files and directories alike. If the root user (the super I
disk!
/ directory, the entire UNIX system wiU be wiped out from the hard

5.4 mv: RENAMING FILES


The mv command renames (moves) files. It has two distinct functions:
• Itrenames a file (or directory).
• It moves a group of files to a different directory.
11v doesn't create a copy of the file; it merely renam
es it. No additional space is consumed on disk
during renaming. To rename the file chapOl to manOl, you should use
mv chapOl manOl
mv simply replaces the
Ifthe destination file doesn't exist, it will be created. For the above example,
t, mv doesn't prompt for
filename in the existing directory entry with the new name. By defaul
overwriting the destination file if it exists. So be careful again.
and moves three files to
Like cp, a group offiles can be moved to a directory. The following comm
the progs directory:
mv chapOl chap02 chap03 progs
11v can also be used to rename a directory, for instance, pis to perdi r:
mv pis perdi r
r exists or not. You can
Like in cp -R, there's a difference in behavior depending on whether perdi
check ?'at out for yoursel£
cp. The messages are the
There's a -i option available with 11v also, and behaves exactly like in
same and require a similar response.

yep, mv a
ii zj
. As shown i~ Fig. 5.1, cp
cp, 11v and r11 w_ork by modifying the directory entries of the files they access
number that is allotted by
adds an entry tp the directory with the name of the destination file and inode rm
t disturbing its inode number.
the kernel. ,replaces the name of an existing directory entry withou 1
removes ~m an entry from l;he pirectory.
ation are in the same directory.
This is a ratheri simplistic view, a~d is true only when source and destin
disk, the file is actually moved.
When you "mv~ a fitJ to directory that resides on a separate hard
systems create the illusion of a;
You'll. appreciate this better after you have understood how multiple file
' ·, '
single file system on your UNIX machine.
I
\ aa · UNIX: Concepts and Applicatio
ns

Filename Inode Filename /node


Nu mb er Number
386444 cp foo foo.bak 386444
.. 417585 .. 417585
foo 499770 foo 499770
foo.bak 509876

mv too bar

Filename lnode
Filename /node
Nu mb er
Number
386444 1'111 foo. bak 386444
.. 417585 .. 417585
bar 499770 ,.
bar 499770
foo.bak 509876
Fig. 5.1 Directory Status after cp,
mv and rm
Th e act ion of na also needs
entry. There could be "sim
to be studied further. A file is
not actually removed by de Ietin g its directory
. file in this or
ilar" entries (ones having the
another directoiy. We'll exa same inode number) .fo r th
mine this directoiy table aga ~ n we take up
file attributes in Chapter 11. in along with its pen nis sIo ns
w
----
5.5 more: PAGING OUTPUT
The: man command dis . . .
plays its output a page at a tim e. This is possible because 1t. •• d its output to
a pager p~o~ram. UNIX offers the sen s placed
.more pager (originally from Berkel
pg, the original pager of UNIX. ey) which has tod~l;~iscuss
Linux also offers more but 1ess is its
more in this section and note the standard pager.
exclusive features of less separately
in the aside on Linux.
To view the file chapOl, enter the
command with the filename:
more chapOl
Press q to exit
You'll see the contents of chapOl
on the screen, one page at a time. As.
also see the filename and percen the bottom ofthe screen, you'II
tage of the file that has been viewe
d:
--More--{17%)

1110re h as a .courole ofinternal command_s that don't show up on the scr


• l een when you invoke them. q,
the command usCd to exit _,re as an ant •
erna com ma nd
. .
' '
.. .. .
Handling Ordinary Files -II
's9

The AT&T and BSD versions of more differ widely in their capabilities and command usage. The
POSIX specification on more is based on the BSD version. You have to try out the commands
shown in Table 5.1, as well as look up the man pages, to know whether they apply to your system.
110re has a fairly useful help screen too; hitting an h invokes this screen.

5.5.1 Navigation
Irrespective of version, more uses the spacebar to scroll forward a page at a time. You can also scroll
by small and large increments oflines or screens. To move forward one page, use
f or the spacebar
and to move back one page, use
b

5.5.2 The Repeat Features


The Repeat Factor Many navigation commands in more, including f and b, use a repeat factor.
This 'is the term used in vi (7.1.1) to prefix a number to a vi internal command. Use of the repeat
factor as a command prefix simply repeats the command that many times. This means you can use
lOf for scrolling forward by 10 pages and 30b for scrolling back 30 pages. Just remember that the
commands themselves are not displayed on the screen--even for a moment.
Repeating The Last Command ( .) more has a repeat command, the dot (same command used by
vi), that repeats the last command you used. Ifyou scroll forward with lOf, you can scroll another
10 pages by simply pressing a dot. This is a great convenience available in more!

5.5.3 Searching for a Pattern


You can perform a search for a pattern with the/ command followed by the string. For instance, to
look for the first while loop in your program, you'll have to enter this: •
/while Press [Enter} also
You can repeat this search for viewing the next whi 1e loop section by pressing n, and you can do that
repeatedly until you have scanned the entire file. Move back with b (using a repeat factor, ifnecessary)
to arrive at the first page.

Note: The search capability in 110re is not restricted to simple strings. Like many UNIX commands
(grep, sed and vi), more lets you use a regular expression to match multiple similar strings. Regular
expressions are discussed in several chapters of this text beginning with Chapter 13.

5.5.4 Using more in a Pipeline


The 11n syntax doesn't indicate this (except mention that more is a filter), but we often use more to
page the output of another command. The 1s output won't fit on the sc~een if there are too m,any
files, so the command has to be used like this: • •
\ 92 \ UNIX: Concepts an d Ap
__.__, plicatio ns
stem
You ca n cancel only thos • ha ve su bm itt ed yo ur se If) bu t the sy
e 1obs th at you ow n (i.e
administrator ca n cane.el
~ny job. cancel is effectiv
., you h . b m ai ns in th e' pn.nt u~ue.U
e on ly w en a JO re q_
it is 1lready being printed,
cancel can't do a thing.
- ed ii
tiote: t-\ost UN\X printers . . .
are of th e Postscript vane ro erly pr in t files forrnattea
Postscript, like th e tiles rfc ty, t.e., they can P P (P sif
822.ps and chapOl.ps ostscript files are tit
identified by the extensio used in the examples.
n . ps.) When you select f ny GUI pr og ra r.i ~
program converts the da Print from th e File ~e nu
ta to Postscript which seive ; a ch conversion ea
plac:e when you use \p as input to the pnnter. 0 5
to print a text file like /et ~ file to print. 0\
Po sts cr ip t co nv er sio n c/passwd. If you have
utility be fo re you us e a tex th e progr 111
/u sr /li b/ lp /p os tsc rip t/p 1 p. 0 n S o Ian•s, yo u ca n us e
os tp rin t before running .
lp.
r"-- ••., "'""'l"i;
1
- .. -·
•- -•,-,._

~U X : Pri~ting with 1 pr
-.._ •~ 1',• •

I
"'·

, ll)q and lpn1 •


i•., ~-
••=- • - - • : . - - l l
~- .,

• . •
Unux uses Ber~\ey's pri us t tia 1
your nting syste
printer configured properly m ~c h supports the lp~ c~mmand for printing.
beforeyou can use l pr. Th ~o
job number: e command normally d~ sn ~r :,o Ut ~1
' • • • •
\l pr /et c/g ro ~p • ·,. •.
. •• •. ··_ .• . ••..'~-
••. •• _
Unux has a rich se t of too
ls that convert tett files to
Postscript Check whether yo
:z ps ~r enscrtpt o n ~
sy st em ._ ~ eventually
~aU~p lpr; yo~ don't have
u have the p ur
to do ~a t 0 :: u t to a
4
Systei_n V, you can print a
specific: nu er. of copies, ch
sp ec ific printer. You
I can also mail completionmb of the job:··· •
oose the title an d direct
. . i]
lp r -P hp4500 fo o. ps . ., •
t lp r -T •th e Li st of RF • • . . Printsonprinterhp4500
lp r -13 fo o. ps cs• fo o. ps •
•• :
• • • Us es thi s title .
i 1pr _-m foo. ps . . '. . . • .-. . . J
. .
'pq displays the print qu . . .
. • .
·
•..

,
• . Prints3 copies • •. •
. .. Mails message after
. completion
.
to
I
eue showing job numb ers. Using one or more job nu ents

l
mbers as argufl'I 1
t~ lc a n ~ e ~ ~
:. ~ t~ u e ~ ~ ~ ~
I lp nn - jo b ·s R :: ~ ~ 3
. · . (·· .··, •• •
. .. • .. Re
The 1pc command is mo oe sa U. Jobsownedby user
by th e administrator to co
nfigure the printer. We'I no
t dlsCU55 prfrtl~
5.7 fi le : KNOWING TH ..,..._. - , : : . . , . ~
E FILE TYPES
Even though we know (so
far) that files arc of three typ
these files. For instance, es, you may often need to know
a regular file may c~ntain more about
UN IX provides the f11 e plain text, a C p~ogram or
command to determine the executable code.
can use it with one or mo type offile, especially ofan ord
re filenames as arguments: inary file. Y~u
$ fi le archive.zip
archive.zip: ZIP archive

_____..

You might also like