SPSA Unit-5 Part-2

21
UNIT 3 UNIX- GETTING STARTED I1 , Structure 3.0 Introduction 3.1 Objectives 3.2 Looking At File Contents 3.3 Your Own Directories 3.4 File Permissions 3.5 Basic Operations On Files 3.6 Changing Permission Modes 3.7 Standard Files 3.7.1 Standard Output 3.7.2 Standard Inpt 3.7.3 Standard Em 3.7.4 Filters and Pipelines 3.8 Processes 3.8.1 Finding Out About Prcceseea 3.8.2 Swing Background Rocuses 3.9 Summary 3.10 Model Answers 3.0 INTRODUCTION In this unit, you shall be introduced to some basic concepts of UNIX like files, directories, processes and standard files. It will be sufiicient to allow you to perform many simple tasks. All the above features are illustrated with several realistic examples. In the coursk of this and the following units you w i l l ~ o c c a s i o n to see in action many of the theomici-4 con- you have studied about operating systems. You will find it interesting and insmaive to correlate theory with its implementation in UNIX. 3.1 OBJECTIVES At the end of this unit you shall be able: To learn to use some simple UNIX commands. To go through the file coitents To change the permission modes To understand the concepts of filters and pipelines To understand what a process is and how it differs from a prqg*un. 3.2 LOOKING AT FILE CONTENTS So far you have not had occasion to look at what is stored inside a file. You have only seen the filenames in a directory listed by the Is command. or moved from one directory to another with cd, or the type of a file shown up by the file command To look at thepctual contents of file like /etc/motd, say % cat /etc/motd This prints the contents of the file on the terminal. The cat stands for concatenate and a~tually cat can be given any number of filenames as arguments. The effect of cat is to join all the files in the order specified in the arguments and.to send them to the terminal screen. When only one file is specified the effect is to type that file on the screen. It makes sense to cat only text files to $e terminal for otherwise the result might not be readable. If you cat a binary file, that is, one which can contain any arbitrary characters including control characters. you are likely to get strange results. Your cursor might jump

description

This Post Is Only For CSE THIRD YEAR STUDENTS FRM WIT.....

Transcript of SPSA Unit-5 Part-2

Page 1: SPSA Unit-5 Part-2

UNIT 3 UNIX- GETTING STARTED I1 ,

Structure 3.0 Introduction 3.1 Objectives 3.2 Looking At File Contents 3.3 Your Own Directories 3.4 File Permissions 3.5 Basic Operations On Files 3.6 Changing Permission Modes 3.7 Standard Files

3.7.1 Standard Output 3.7.2 Standard I n p t 3.7.3 Standard E m 3.7.4 Filters and Pipelines

3.8 Processes 3.8.1 Finding Out About Prcceseea 3.8.2 S w i n g Background Rocuses

3.9 Summary 3.10 Model Answers

3.0 INTRODUCTION

In this unit, you shall be introduced to some basic concepts of UNIX like files, directories, processes and standard files. It will be sufiicient to allow you to perform many simple tasks.

All the above features are illustrated with several realistic examples. In the coursk of this and the following units you w i l l ~ o c c a s i o n to see in action many of the theomici-4 con- you have studied about operating systems. You will find it interesting and insmaive to correlate theory with its implementation in UNIX.

3.1 OBJECTIVES

At the end of this unit you shall be able:

To learn to use some simple UNIX commands.

To go through the file coitents

To change the permission modes

To understand the concepts of filters and pipelines

To understand what a process is and how it differs from a prqg*un.

3.2 LOOKING AT FILE CONTENTS

So far you have not had occasion to look at what is stored inside a file. You have only seen the filenames in a directory listed by the Is command. or moved from one directory to another with cd, or the type of a file shown up by the file command To look at thepctual contents of file like /etc/motd, say

% cat /etc/motd

This prints the contents of the file on the terminal. The cat stands for concatenate and a~tually cat can be given any number of filenames as arguments. The effect of cat is to join all the files in the order specified in the arguments and.to send them to the terminal screen. When only one file is specified the effect is to type that file on the screen.

It makes sense to cat only text files to $e terminal for otherwise the result might not be readable. If you cat a binary file, that is, one which can contain any arbitrary characters including control characters. you are likely to get strange results. Your cursor might jump

Page 2: SPSA Unit-5 Part-2

UNIX Operating system-I hither and thither on the screen, the screen might get cleared from time to time, the terminal bell might sound or your keyboard might get locked. These effects are caused because the cat command is sending the contents of the file to the terminal. If the file contains character sequences tnat have special effects on your terminal, you will observe these effects occurring spontaneously. While this will not do any harm, it can be disconcerting or annoying and in any case will not probably be very useful since you will not be able to make sense of what got typed ori the terminal.

If the text file you type is a large one, the output will not fit on your screen. You have already seen that you can use AS and "Q to control the stopping and resumption of the output and thus read what is in the file. However if the file is more than a few screens long, it will be difficult for you to keep suspending and resuming output again and again. Moreover you will have to opemte the keyboard dexterously if you want just enough of the output to scroll by but not too little or too much. If you are a trifle slow, some unread output might disappear before you are able to read it.

To look at atext file screen by scrsen, you can use themore command.

% inore letcltermcap

This cammand shows you one screenful of the file and then pauses until you ask it to proceed further. You can now examine the contents at leisure. When you are ready to look at the next part of the file, you can press the spacebar for seeing the next screenful. You can move one ot more lines forward by pressing a number before the spacebar. You can also do this by presging the number of lines to move forward followed by the RETURN key. Note that normaldy commands taken by more do not require you to press the RETURN key, so that as soon as you have pressed the spacebar the display moves forward by one screenful. You can search for a text string by saying '/' followed by the search pattern. The display will then scroll forward to show you the screen where that pattern occurs next. In general you cannot move backyards in the file by using this command. To terminate the display of the file, just press 'q' and you will get back your prompt.

There are selveral other options available with the more command. You should refer to the documentation and experiment with all the options so that you understand them thordughly.

There is andther command called pg which has a similar function. You could use this if more is not available or is not to your liking. You can compare bcdi of them if both are available on your sysdem. The ability to look at files in manageable screensful is often very useful, so be sure to know at least the basic options to these commands.

fhere is on@ more command that is useful when you want to look at only the last few lines of a file. To see the last 20 lines of a file you can say

% tail -20 Ietclterrncap

If the numbfr of lines is omitted a default value of 10 lines is assumed. So you now know how to look at the last line of a file. You can also use tail to start looking at a file from any line number. For example

% tail +15 /etc/te~mcap

wili show the contents of the file Ietcltermcap from line 15 onwards. You could also use the more commjand to achieve the same result

% bore +15 Ietcltermcap

However there is a difference between these two commands. When you use more, the display will pause at the last line of the screen with the usual prompt, and pressing the spacebar wal show you another screenful. The tail command will show the rest'of the file without a pause, unless you use AS and AQ to stop and start the display.

6 ' . : 2 ~ ! : Yo:jr Progress 1 - 1. I ry usitig cat on a direc:ory. What do you obscrvc?

Page 3: SPSA Unit-5 Part-2

V'iiat t13pi:cns if you cat a file which does not exist?

......................................................................................................................

3. LC.' stiy to c,hangc tht: baud-rsli: setting for you terminal. It will asudly be 9600 if you ark. on a ditcct serial conr~ectiorj k) your machinc. Reduce dre setting and sm the result o! I.IS!~I~ n cat.

4. mrbre md yg havc many options. Find oilt how to use these. other op~:)ns lo the cc.i.t:lnal~ds. I-'or cxarnplc, more by defkiilt scro?li: llle riisphy upward anti stops when the nc:i t screen is about to bc rcachcd, keeping orlc line konl rhe old screen aL the top (the lire which was earljsr at the bottom). This kind of bd~aviour can make it difficult to rcad wltzn rnorc is doing n rcfresh:Hnw do you make Inarc: refresh a screcri by changing the i i ~ w starting Crona the top of the screen so that a {me is not didlrrbcd uztii it is i~ turn to bc ;rf~:shed?

3.3 YOUR OWN DIRECTORIES

In the earlier examples we have assumed that you had somehow created some directories and files, which we used to explore the Is and other commands. Let us now see how to create our own directories. In the next section we will also take a look at what the file permissions mean. You had first come across file permissions when you learnt about the 1s command in section 2.3.2. But first type cd to reach your home directory. Most likely you have no files or directories here (unless you sought an expert's assistance to create some before reaching this section). So using the Is command without any options will give you no output at all. Let us now create a directory here, under your home directory.

% mkdir nlp

Now use 1s to see that nlp is now listed as a directory. You can cd to nlp and see the directory listing there, which will be empty.

The mkdir command takes one or more arguments and creates the directories as specified. You can thus say

% mkdir crypt crypt/src

to make a directory crypt under the current directory and a directory src under crypt, both in one operation. Thus the arguments are serviced in order, from lefr to right. So now you know what would happen if you tried to create a directory learn and a directory c++ under it like this

% mkdi learn/c++ learn

The first directory learn/c++ cannot be created because learn does not exist at that time. You will find hat mkdir complains about this. However it will create learn under the current dirzctory, that is, the directory from which you executed the command. So to create both the directories, you should have mentioned learn before learn/c++, whereupon both directories would have got created properly as in the example before this.

s

What happens when you try to correct your mistake by using the command agein? Let us now try

% mkdir learn learn/c++

As you mtist have deduced, mkdir complains that it cannot make the directory l e m , This is because the last Lime we had used the command this directory had got created. However this ti~nc the directory learn/c++ does get created.

UNIX Gettlng Started ll

Page 4: SPSA Unit-5 Part-2

UNIX Operating sy~tan- I So you now know how you can create more than one directory in only one invocation of the mkdir command. Suppose you now want to set up your private directory structure at one stroke, requiring the creation of many directories. You can say from your home directory

% mkdir nlplsrc nlpldoc nlplinclude cryptldoc crypt/include\

learn/XllRS le-X nlplgrammar

The thing to notice about the command here is that we have given it so many arguments that they do not fit in one line at all. If such a situation occurs, you can simply keep typing and your input will automatically wrap around to the next physical screen line unless your terminal has been set to behave otherwise. However many people, especially those new to the subject, find it disconcerting to see such a long input line getting folded onto anothcr physical lihe on the screen. If such is the case, you can at any time press the T followed by a newline to reach the next line on the screen. As long as the newline is the character immediately after the T, the special meaning of the newline to the shell is turned off, as you saw in section 2.2.3. To the command it is still a newline, but as you already know, arguments to commands can be separated by white space, not just a space, and a newline is a white space character. Having given the newline yourself like this, you are less likely to feel. disorientd on seeing such a long line. At the end of the command you can give a newline as usual to tell the shell to go ahead and execute the comdtand.

If you now look at your directory listing with 1s you will find that only the directories directly under your home directory are listed. Thus

crypt learn n l ~

The subdirectories that you created under each of these will not &ow up if you use only this simple fo@ of the 1s command. You can look at the contents of these by saying

46 1s crypt learn nlp

whereupoh you will see the contents of each of the arguments that are directories. Also, as you have seen in section 2.3.2, you can see all files and directories under your current directory by saying

Now is a good time to learn how to delete directories. This is achieved by using the mdir command and giving it the names of the directories you want to delete as arguments, Let us see how this command works. First make a few directories as follows

% mkdir junk junklsrc junklsrcldoc junklobj junkfdoc

Of course all thabwe have here are directories with no ordinary files anywhere. Now let us try to reqove them

k rmdir junk . You will bet a message saying that the directory is not empty. So to be able to remove a directory with this command, that directory must not contain any files of any kind. Hence we have to say

OBo rmdir junkldoc junklobj

This succleeds and leaves us with only the junklsrc directory. Now

% rmdir junk/srcldoc junk/src junk

will allow you to emsq all the directories you just created junk downwards. a

Check Your Progress 2 1. Yod check the contents of a directory heavens by saying Is heavcrls :lad find no f~le,; in

it. But rmdir heavens does not work. What is the matter?

Page 5: SPSA Unit-5 Part-2

2. There is :in cmpty directory vanish. You cd to this and verify that it contains no files. Now you say 'rmdir .'. What happens? Check your current directory with pwd and explain what you observe,

...................................................................................................................... 3. Can you delete a parent directory with 'rmdir ..'?

3.4 FILE PERMISSIONS

It is now time for ys to explore what file permissions are and what effect they have on its accessibility. You can see the file permissions for a file by saying

drwxr-xr-x 2 kumarr users 32 June 19 23:04 crypt

drwxr-xr-x 2 kumarr users 32 June 19 23:04 learn

drwxr-xr-x 2 kumarr users 32 June 19 23:04 nlp

As you already know, the first column of the first field has a 'd' in it if the file is a directory. So we can see that crypt, learn and nlp are all ditories. Then you see 9 columns which specify the file permissions. The user community in UNIX is divided into three categorie* owner, group and others. The owner is the person who first creates the file. Several users at an installation can be made part of a user group. Such a facility is useful in keeping people working on the same project categorised together, and UNIX was first conceived of as an operating system which would allow groups of programmers to work together and share information. All group members form the second category of users. Finally the rest of the community is lumped under others, which are users who are neither the owner nor part of the same group. In the example shown. the owner of the directories is kumarr and he belongs to the group users. Other users like khanz might also belong to this group.

Having understood this categorisation of UNIX users, you can now begin to study the permission modes. Every file has three possible modes of access- read, write and execute, represented in the directory listing by r, w and x respectively. A file to which you have read access can be read by you, which means you can look at its contents by using any method like the cat command. If you have write access to a file, you can alter its contents. Execute permission is relevant in the case of executable files like those that we have seen in /bin, or . for shell scripts, which we will study later. Yw can run or execute a file only if you have execute permission on it. Execute permission does not mean anything in the case of text files, nor actually for any file that is not an executable, except for d i to r ies where this permission has another meaning.

Now you know enough to understand the permission information. The nine columns are divided into three parts- owner, group and others -of three columns each. The permissions are specified in the order read, write and execute. If a permission is available, the corresponding letter is shown, while the absence of a permission is indicated by a hyphen. So rwx means the category concerned can read the file, can write to it or alter its contents and can execute the program which the file contains. r-x means the file can be read or executed but not altered or written to, because write permission is absent. r- means the file can only be read, and -x means it can only be executed. - - means there are no permissions available and such a file cannot be accessed at all. However you can still see an ordinary file like this listed in a directory listing taken in the usual way. So you see that the permission columns in the listing shown above mean that the owner has read, write and execute permission, whereas other members of his group have read and execute permission but no write permission. Similarly others, that is, users who are not part of the owner's group also have read and execute but no write permission. Thus if you want to have all the permissions on a file, while denying group members write permission and allowing othek only execute permission, the permission modes should be rwxr-x--x.

UNlX - Getting Stnrted 11

With this knowledge you should again'look at the UNIX system files h d study the owners and permission bits of each. You will find that all users have execute permission on the files containing system commands. This is obviously necessary because otherwise you could not

Page 6: SPSA Unit-5 Part-2

UNIX Opcrating Systcm-I use those commands. If possible, ask your system administrator to remove your execute pcrmission on the Is command for a short while and then try to see your directory listing. If you are at a large installation where this kind of thing might not be possible, you can either wait until you know more about UNIX to be able to see the effects of the absence of permissions, or ask somebody to make a copy of a system command in your directory, remove execute permissions on it and try to run it from you directory, taking care that you do not execute thd system version of that command.

So far we have talked only about ordinary files and what file permissions mean in their case. But directories are also files, as you have seen earlier. Do the permissions all have the same meaning whew directories are concerned? If so, what is it like to execute a directory? Let us delve a bit into this and find out some answers.

First of all. youlmust understand that since directories are special kinds of files which contain information about other files. the permission bits have somewhat different meanings than what a hasty giess would suggest. Before we even look at what read permission for a directory means, make sure you have done the exercise (1) of section 2.3.5, which asked you to cat a directory and report what you saw. If you tried the cat command on a dircctory which has some files you will see a long line of words, at least some of which you should be able to identify as names of files in the directory. So you see that the contents of a directory are the names of files under it.

Now it is easy lo deduce what read permission on a directory could mean. If you can read a directory you can cat it and it follows that you can do an 1s on the directory. In the absence of read permission you will not be able to look at the directory listing.

What about wrike permission? If you have write permission on a file you can change its contents. In thesame way having write permission on a directory allows you to change its contents. What hoes that mean? Creating, renaming or removing files would mean altering the contents of that directory. So it follows that having write permission on a directory enables you to create, rename or delete files in that directory.

I

Beginners often find it a bit difficult to grasp this point though it is not really hard to understand. YOIJ should remember that having write permission on an ordinary file allows you to charngo the contents of the file but does not allow you to delete or rename the file. That is possible only if you have write permission on the directory containing the file. Later we will see how his hct could create a security lapse in some situations.

Lastly, coming lo execute pcrmission you would agrce that there is no way you could execute a dlirectory corresponding to the normal sense that Lhe operation refers to for an ordinary file. Fdr a directory this permission bit determines whcther you can cd to the directory or cancopy files from that directory (this only if you have read permission on Lhe directory as wcll). This permission is olten called search permission. To be able to cd to any directory you must have search permission on every component of the absolute pathname of the directoq. If Bearch permission is absent on any componcnt, all files and directories on that component b d below it become inaccessible.

Apart from these permissions there are some othcr permission modes which you will comc across. We will uke these up in the unit on system adminisuation. For now it will be sufficient to knob that some other permission modes exist so that you do not gct taken aback if you find characters other than r, w or x in the permission modes of a directory listing.

Check Your Prlogress 3 . - .

p 1 S , ' ; ) I , : < : ; 1. What are tde narncs which are not files doing in thc dircctvry? Thcy arc .:x :c% whichhavd lxcn dclcted from that dircctory. Find out how to %rib: a p;ogir:;-i: ti; 11:,: i illis

1 \\arjtc, g,c !,; ~ f > ~ ? : ; ! > . : ~ j ~ ~ j that are or hcrc part of the directory. If you do lhis you car1 casi g. yourself. Hbwevcr Lhc list in the directory is not sorted in niiy o;ti:r and ~ h c i i i ~ . .ic

appe.ar in tlie order of creation. It is thc Is command which do-c,s,thi. 1:clr:;. pr,:i.-:r:!i ::;

you wjlh the output.

2. Try executing a dircctory on which you do not havc scar,h pcnnibsion, mi x . 1 :., r ;:I: which you do have it. What happcns?

Page 7: SPSA Unit-5 Part-2

mIX -Gettifig Started I1

3. Can you look at thc listing of a directory if you do not have search permission on it? Why?

...................................................................................................................... 4. Can you remove files from a dircctory if you lack write permission on them?

3.5 BASIC OPERATIONS ON FILES

We have covered a fair amount of ground in UNIX but we still do not know how to create or remove files. We will look at some basic file operations in this section. You will then at last be able to have some files of your own in your directory instead of having to rely on system directories to be able to see a non- blank directory listing.

Copying Files Until you learn about text editors in a later unit in this block, you will have to make files of your own by making a copy of an existing file or by running a program which creates a file. Let us now study how to make a copy of a file. Make a directory learn in your home directory and cd to it. Now say

% cp /etc/passwd passwords

and look at your directory listing. You will find that you are the proud owner of a file called passwords, which gets creatcd in the current directory. This file will be an exact copy of the original file /etc/passwd. You can now look at the contents of both files and generaUy verify that lhis is probably the case, although you will not be able to easily do an exact match visually and you do not yet know of utilities which can do it for you. For the timebeing you can try copying short files to verify hat it seems to be so.

The cp command in his form takes two arguments of which the first is the source, or the file of which a copy is to be made. The sccond argument is the destination. or the name of the file which is to hold the copy. The names of the files can be specified as absolute or relative pathnames and the current directory is h e default, which is why in the example above the ncw file got created in the current directory.

Here we copied the file into our own directory with a different name, but we could have also given a command like

% cp /etc/group group

This will create a copy of /etc/group in the current directory and the copy will also be called group. Anohcr way of doing this is to omit the name of the destination file and specify only lhe destination directory. In such a case the copy is given the same name as the original. Thus

k % cp /etc/motd . I

or

will create files called motd and termcap in the current and home directories respectively.

You can copy scveral files from several other directories into a single directory by enumerating all the source files and giving the destination directoq name at the end. When you use this method the names of the files are preserved, that is, the copies have the same

I names as the originals. Thus ;

% cp /etc/issue /etclrc /usr/include/stdio.h .

Page 8: SPSA Unit-5 Part-2

U ~ l x oprrUng SJ&JD-# will c m t e tiles called issue, rc and stdi0.h in the c m n t directory.

So far we have looked at cases where there was no file with the same name as the target a M y present. What would happen if a file with the same name as the target did exist? In keeping with the general philosophy of UNIX, which is to silently obey whatever commaqds the user gives (thereby respecting the intelligence of the user and giving him credit for being responsible enough to know what is good for him), the target will be unceremoniously overwritten by a copy of the source. So before issuing the cp command you must ensure that this is what you want, otherwise you will have lost the original contents of the target file.

Let us now' see some m n s which can cause cp to run into a problem. One is if you uy to create a file in a directory where you do not have write permission, or when you try to overwrite an existing file on which you lack write permission. cp will then complain that it cannot create the met. Another problem could be the absence of read permission on the source, or running out of disk space while copying.

The cp command pleserves the permission modes of the original but changes the owner and grwp to that of the user making the copy. Also there is regrettably no straightfornard way of recursively aopying files from subdirectories under a directory.

2. See whdt h:lpp::ns if you try c ~ p y ,l fitl: 10 i:y;i:ij. g-:, I:;rc 7: . .,.., . . . . . . . ~ b,Lt,:,'. 7 : . ;%.I ::I;; r . . . . rJ .+ . - > x .,. :.\ . -' ' 2

to the source thus

3. If the sobce does not exist or is unrcori:!bl? hu: rhc ;?r;,ct r;!rcli:dy cxis~r,, wh:!: h:q!!rnl; to the target after the cp cornm;!nd tcrtrlinarcs !,abnorni..:!?l :.''

4. What happcns if whilc copying sevcra). I'!cs in iinc invi.x:i!ic::i (-:f cp thr copy cop;r;i;ion fails for one of the files?

5. Set what happcns if there are several files with different contents, cach in a tiiffcrent directory but with the same name and vou try to copy them in orac inwxation of cp to one directory.

Renaming Files We shall now look at thk question of changing the names of existing files. Look at your learn directory witH

% 1s -x

group issue motd passwords rc stdi0.h tepcap

Page 9: SPSA Unit-5 Part-2

These are the files we copied into this dimtory in the previous sub-section. To rename motd to headline say

% mv motd headline

% 1s -x

group headline issue passwords rc stdi0.h termcap

You can check the contents of headline to satisfy yourself that they have "not changed. As you can see from the directory listing. the original filename no longer exists.

Lest you wonder why the command is called mv for move rather than something like ren for rename, the usage we have seen so far is only one aspect of the mv command. The primary purpose of this command is to move files from one location to another. As a side effect it.is possible to change the names of files in this process. If the move is done within the same directory this operation is meaningful only if the name is changed, which is of course the same as renaming the file.

The capabilities of this command are similar to cp, except that the original or source disappears when the command completes. If rhe destination of the move is a different directory you can move several files at a time. Try this out by making another directory of your own

% mkdir -/learn/leam

You will find that the files group and headline are no longer present in -/Yearn but are now in -/leamilearn.

If a move is being done within the same file system the mv command is quite quick because not much disk activity is required, irrespective of the amount of data in the files. Also there is no danger of the command failing for lack of space because no extra space is required on the disk. However the picture changes when the move is being done across file systems. Since the super block and the i-node table are different (you will learn about these in the unit on system administration) for different file systems, a file can be moved from on file system to another only by copying it to its destination and then deleting the original. This is just how mv works. Therefore in such a case you can find that mv fails because of lack of space in the destination file system. Moreover the command will take longer to execute because data has to be physically copied to the destination file system. But there is no danger of losing the original if the command fails because the original file is deleted only after the copy to the destination has been completed successfully.

4 s with the cp command if the new name is the name of an existing file that file gets silently overwritten by the new file. So be careful on this count.

C'l le~*k Your Progress 5

1. i'ind out what hq)lxns if you issue an mv command with both the arguments the s'une, 1;ke

';b rrlv filel filel

2. 'What happcns if a file with the same name as the target of zn mv exists but is write ;!rotcc tcd?

Deleting Files By now you have acquired a sprinkling of files in your work area, and it is time you leamnto delete files you no longer require. This can be done using the rm command

% rm termcap

Page 10: SPSA Unit-5 Part-2

UNIX Operating system-I If you look at your directory listing you can see that the file termcap is now gone.

The rm command takes any number of arguments and deletes all files specified in them. The files can, as usual, be specified using absolute or relative pathnames. However the command will refuse to touch directories. So if you say

% cd; rm learn

rm: )earn directory

UNIX infoqs you that learn is a directory and leaves it intact. If you do not have write permission id a directory you cannot remove any files from it and the command will fail. But if only the filb is write protected rm tells you the permission modes of the file and asks you to confirm whether you really want to delete it.

% rrn protected

rm: protected 444 mode? (y/n)

Now if you type any response starting with a y (for yes) the file will be deleted after you press the R E W N key. Any other response will leave the file as it is.

A related option to rm is the -i option which tells rm to print the name of the file and wait for your confirmation before deleting it. But now the mode of the file is not shown. The converse of this option is the -f option (for force) which tells rm to delete the file silently without asking any questions, irrespective of the permissions. This of course does not mean that you can delete files without having the appropriate access rights, only that files you can delete will be deleted without any further reference to you.

At lcast in tha beginning while you are new to UNIX it is wise to use the -i (interactive) option to rm, lest you inadvertently lose important data because of a command wrongly given. Remerhber that in UNIX a file once deleted cannot be recovered - it is gor?e for ever.

Now let us look at a very powerful form of the rm command. The - r (recursive) option deletes all files in the directory specified and recursively in all subdirectories of the directory, including the subdirectories themselves. In other words it cleans everything from under that directory including the directory itself. Thus it is far more powerful than rmdir, which refuses to destroy non-empty directories. In one command you can destroy the entire directory trce using the -r option

will wipe out everything under your home directory. At this point you could afford it because you had not laboured much to create whatever files you had. But imagine a situation where you wipe out months of effort at one stroke. So be very careful while using this option. The most sweeping form of the rm command is

which will wipe out clean out everything on the disk except any unmounted file syslems. Since usually rlll partitions are mounted at boot time, you will end up wiping out the entire installation including the rm command and the UNIX operating system itself (sec the unit on system administration for an explanation of the mount command). Even if you havc a complete backup, it will take a lot of effort to restore the installation to its original slate. Therefore you must be very careful indeed when using rm - r. We see no situation where you might need to use rm -r /. Removing everything on the disk can be done more thoroughly by other means.

You are now encouraged to try out rm -r / on your installation as an ordinary user! Why do we contradict ourselves in the space of two sentences, you might wondcr. The point is that rm -r can and will delete only those files which the permission modes allow. While the superuser can delete any file irrespective of permissions, an ordinary user will not be able to cause any damage to an installation which has been carried out properly. If you are able to cause any problems to others or to any other part.of the installation it is a signal to the system administrator ahat all is not right with security at the insrallation. But do not do this as superuser unless you know you can reinstall UNIX on your computer!

Page 11: SPSA Unit-5 Part-2

Links between Files As we have said before when talking about the 1s command it is possible for a file to have more than one name. If there is a file in your home directory called motd, you can give it another name like this

% In motd headline

Now if you look at the contents of the files you will see that they are the same. You can create a link between the two fib names by using this command. If you wish you can create more links subject to a system imposed limit. Of course one rarely has occasion to have more than a few iinks to a file. You can link a file to an existing filename too

9% In -f password hadline

Now if you look at headline it w~ll have the same contents as password rather than motd as was the case till now. Actually headline and password are now two different names for the same file. The name headline has got detachad from motd and has got attached or linked to password.

You cannot link files across two different file systems. This is because the super block, which stores file system information, is different in the two. However later versions of UNIX permit what are called symbolic links between files in different file systems, but we will not look at them in this block. The links we have seen here are also called hard links as opposed to the symbolic links mentioned. Let us now create a few more links to headline

% In headline sensation newsworthy

S'udy the directory listing now.

% Is -1

-rwxr-r- 4 kumarr users 1690 June 27 03:W headline

-rwxr-r-4 kumarr users 1690 June 27 03:09 newsworthy

-rwxr-r- 4 kumarr users 1690 June 27 03:W passwd

-rwxrLr- 4 kumarr users 1690 June 27 03:W sensation

Although these look like four different files, the second field in the listing tells you that each of them has 4 links. This does not however mean that they are linked to one another. For the moment you can assume this because we just created the links ourselves.

What is the difference between creating links and making copies of files? When you create a copy of a file, there is physical copying of the data in the source file to the target. So some disk space will be used up in storing the copy. Also, if you now alter the source, the target is not affected, and vice versa because they are two different, independent files. But if two files are linked there is only one physical copy of the data on the disk. Altering one file automatically changes the other one because there is actually only the one file although it has two different names. Extra disk space is not required to store the linked file.

So if you now delete the files above one by one and keep observing the directory listing you will find that the number of links keeps reducing by one in all the remaining names. When the last link to a file is removed the file gets deleted because there is no name by which it can be accessed, and the disk blocks it occupied eventually get reallocated to other files.

Can you now look at the listing of cp, mv and rm in the /bin directory? You will find that each of these executable files has three links. Actually the code which performs all these three fucctions is the same. Depending on the name the executable was invoked with, the code performs somewhat different tasks. You have only to recall that mv has to do both a cp and an rm if the move is across different file systems, and the close relation between these three commands becomes at once apparent.

Check Your Progress 6

1. See if you can link an ordinary file to a directory. Can you link two directories?

UNIX - Cettlng Started 11

45

Page 12: SPSA Unit-5 Part-2

2. Can you crcate a link to a file in a directory where you have no write. pen!iicsion?

3.6 CHANGING PERMISSION MODES

We will now see how to change the pennission modes of files and directories. So far we have had occasion to look at various commands, many of which have to do with files of various types. We have seen that the permissions on the files make a great difference to the actions of these commands. For example the cat command will usually type a file on the terminal but will refuse toi do so if the user does not have permission to read the file. So we can keep our files protecW from ordinary users if wish or need to do so by changing the permissions on it appropri~dy. The command to do this is chmod. The permissions on a file can be changed only by the o h e r of the file or by the super user. The owner, as you have already seen, is the user who created the file. This creation can be by any means, for example, by using a text editor, througjh a user written program or by simply copying an existing file. Note that having permissions On a file does not amount to owning it. If you can read somebody else's file, it does not mean that you can prevent others from doing the same, but you can establish such protection for a file of your own. Also do not get confused between the original file ar 1 a copy you might have created. having only read access to the source file. You can change your copy in gn~fashion you wish, but you will not be able to alter the original.

There are two forms in which you can use the chmod command. Let us look at the absolute method fust, as it is slightly easier to understand and use. In this the pcrm;ssion mode desired for thq files is given to the command in an octal notation which we will explain shortly. The mode of the file then gets changed to what was asked irrespective of the permissions before the command was run. The form of the command is thus

% chmod mode filename

where filename is a list of one or more files whose permission modes are to be set to mode. If the permission bits are mode to start with there is no effect on the file or files alter running the chmod cortnmand.

You know that file permissions are specified by 9 columns, for example rwxr-xr-x or rw-r-r-. In Che absolutc method the presence of a permission is indicated by a 1 and its absence by a d. The resulting 9 bit binary number is then converted to octal. This octal number is what has to be specified as mode for the chmod command.

You know thai a binary number can be easily converted to octal by making groups of 3 bits starting from lhe right. Now convert each group into octal as if it were a single numbcr. The resulting string of octal digits is the number in octal. Thus --

rwxr-x-x

can be written in binary as 11 1101001 after replacing each permission by a 1 and each hyphen by a 0. This binary number can be written as 1 1 1 101 001 after grouping the bits in threes. The oc@l form of the number is thus 751. So to convert a file to this mode say

% chlhod 755 progfile

This will give bgf i l e the permissions rwxr-x-x. Likewise rw- r-4- in octal is 644. So you can provide these permissions to your file motd by saying

% chmod 644 motd

Instead of one file you can set the permissions on several files at the same time (all to the same value) by listing the files after the mode. So

9b chmod 0 motd passwd

will make their ~rmissions rw-- . Thus you can read these filcs or change them whereas nobody else (except root) can even rcad them. So

8 khrhod 0 passwd d

Page 13: SPSA Unit-5 Part-2

will mean nobody has any permissions on the file passwd and even you will not be able to read a file of your own with such a set of permissions. However you can change the permissions anytime since you own your file. Also the super user can change the permissions of any file.

Let us now look at the symbolic method of telling chmod the mode. Here h e permission types are, as always, r, w and x. In addition there is a set of characters which specify the target of the aclions. The targets can be u (users). g (group), o (others) or a (all of these). The actions are + t add a permission, = to set it absolutely and - to r~m03e a permission. So you can say (there must bc no spaccs in the mode argument)

% chmod a+x progfile

to allow everybody to run progfile, irrespective of the earlier execute permissions on it. However this is different from saying

% chmod 1 11 progfile

because this would remove read or write permission for everybody, whereas in the earlier case, those permissions would have been left untouched. If the owner had read, write and execute permission, he would retain it. If the group earlier had read and execute permission it would continue to have that privilege. If others had no permission they would acquire exccutc pcrmission. One can rcmove read and write permissions for others by saying

% chmod o-rw progfile

Onc can specify absduaepermissions by saying

% chmod u=rwx,g=rx,o=x progfile

Here the different target categories are given different permissions on progfile by separating them with commas. No spaces should be present in the argument, otherwise only the first part will b c a e n as the dcsired mode. The portion after the space will be treated as a file name which has to be assigned those permissions.

Most people find the numerical way easier to usc. Howcver if one does not want to alter some pcrmission bits, thcn thcre is no straightforward alternative to using the symbolic mode. For example, if you want to deny others any permissions on a file but do not want to altcr your own or your group's permissions, you can say

% chmod o-rwx proglile

But to achieve the same result using the absolute method you would have to fust determine the existing permissions. Suppose the value is 644. You will now have to~say

% chmod 640 progfile ,

If the initial permissions were 666, you need to say

% chmod 660 progfile

instead. If.using the symbolic method you wohd not need to wony. The command you need to give remains unchanged since the o action leaves the u and g permissions intact.

3.7 STANDARD FILES

We have seen quite a few UNIX commands by now, and you must have observed that many commands produce or can produce output on the terminal screen. Likewise many comnlbnds can lake input from the keyboard. Actually these commands have been written to accept input from a standard input file and to produce output in a standard output file. Usually these standard files are set to the keyboard and the termical screen respectively. Let us look at this in somewhat more detail by studying some examples.

3.7.1 Standard Output If you makc a list of commands you have leamt so far you will find that many of them oroduce some output.-For instance let us say

Page 14: SPSA Unit-5 Part-2

which prinls the calendar for the current month and year on the screen. In practice there arc very few commands designed to produce output on the screen specifically. The programs arc written to produce output on what is called the standard output, and,WIX sets the standard output to be the screen by default. That is how the dutpL-kap~ens'b appear on the tcrminal.

The shell, which interprets all your commands and passes them onto the UNIX kernel for execution, has p facility to alter the standard output. In other words, you can define a file, rather than the screen, to be your standard output. (The terminal screen is also a file as far as UNIX is concerned, but we will look at this only in the unit on system administration.) To do this you need to say

% cal calfile

There can be zero or more spaces before and after the sign. This sign indicates that the standard output of the command preceding it should go to the file specified to its right rather than to the terminal screen. This is called redirecting the standard output In the present case the calendar fot the current month will be placed in the file calfile. You can verify this by

% cat calfile

although you could have redirected this output as well

% cat Galfile catfile

1s that not a way of copying calfile to catfile? Note that the file to which output gets redirected gets overwritten if it already exists, although it is possible to arrange matters such that a command which would have overwritten an existing file does not get executed. When the shell sees the sign it first creates an empty (zero byte) file with the name given on the right of the sign. If such a file exists it gets truncated to zero bytes. You can verify this easily by

% 1s -1 lsfile

If you now examine lsfile by using the cat command, you will see a 0 byte file called lsfile shown as one of the files in the current directory. This is because a zero byte lsfile was created before the 1s -1 was run.

There is anothefi operator which appends output to the fde specified rather than overwriting i t This is achieved by

% calO6 1994 > calfile

Now calfile willcontain the calendars for the current month as well as June 1994. Compare this with

% calW 1994 calfile

wbich leaves only the calendar for June 1994 in calfile.

Thus the > sign is safer to use because it never destroys any data, but this operation will keep adding to the file, and it can sometimes be difficult to make out what part of the output was produced by yow last command and which portion is the outcome of previous redirections or was simply the miginal contents of the file.

Check I'our Progress 7

1. What 1i:lppcns i f you redirect the output of an operation on a file to the same file? For inst:~ncc, find out the result of

3.7.2 Standard Input Just as many coqmands produce output on the screen, some commands take input from the keyboard although most take input from files. Look at an aspkt of the cat command you have not studicd so far

Page 15: SPSA Unit-5 Part-2

% cat b%IX - Gctting Startcd 11

The result of this is deafening silence. The uninitiated might wait several minutes before aborting the command, thinking there is something wrong because the system does not appear to be doing anything at all. The truth is that cat can take its input both from the standard input as well as from a file. However the output is always produced on the standard output. If any filenames are specified they are used as the input but if none is mentioned the input is taken from the standard input. There are also some commands which take input only from the standard input.

In the present case no filename ha.$ been specified and cat is waiting \for input from the standard input, the keyboard here. So if you type something cat writes it out to the standard output and the effect is that of echoing your input.

A foolish consistency is the hobgoblin of liltle minds - Emerson

A foolish consistency is the hobgoblin of little minds -Emerson

(Actually if you had given the command just as shown then the above is not strictly correct. The cat command will buffer your input and when that buffer is full it will straightaway wrife it out onto the standard output. So you will probably find that you have to type several lines of text before you see it again on the screen. However if you say

% cat -u

the result will be just as described, for the -u flag calls up cat in unbuffered mode.) If you want to put an end to your misery you can terminate your input file by saying Ad, thereby causing cat to finish and present you with your prompt.

To redirect standard input, say

% cat catfilesrc

whereupon cat will p h t the conten@ on the screen. This is just the same as \

% cat catfilesrc

because cat can take its input from a file as well. So to copy this file to catfiletarget, you can say

% cat catfilesrc catfiletarget

% cat catfilesrc catfiletarget

'Thus you can redirect both standard input and standard output in the same command. Some commands do not take input from the standard input. In such cases redirection of the input is not possible, as with the Is, cp, mv, rm or who commands.

Clreck Your Progress 8 1, How can you create text files with cat? Can this method be used to alter an existing file?

Remember that redirection is a facility provided by the shell, not by the command. The com- mand being run does not know or care what its standard input or output are connected to, and it continues to use them. So the command has to be designed to take input fmm the standard input if redirection of input is to be possible. Thus you cannot say

% c'p cpsrcfile

because cp does not take its input from the standard input. Similarly output redirection is not possible unless the command is designed to write to its standard output.

3.7.3 Standard Error So far we have seen the effect of redirecting the output of some commands that completed

Page 16: SPSA Unit-5 Part-2

UNIX Oper~l.il~g system-^ successfully. QE us look at this a bit more closely. For example, if there is no command like gab, my

% gah iahfile

If you do so you will find that you get a protest message from UNIX on the terminal but that gahfile is empty. similarly

produces a message on the terminal but nothing in Isfile. Why does the redirection fail? After all the command did produce output.

The reason is that there is a third standard file in UNIX, called the standard error. UNIX programs and utilities are usually designed to provide &or messages in case there is something wrong and the program is not able to proceed as expected. Such messages are often referred to DS diagnostic output because they can help the user diagnose the reason for failure. This kind of output is usually written to the standard error file. Usually the standard error is also conrlected to the terminal by default, but like the standard input or output, the standard error can also be redirected To do this in the C-shell say

% gah Bgahfile

This will Glace both the standard output and the standard error in gahfile. Here it will have only the error message telling you that tkre is no file called gah. How do you place the standard output qnd standard error in different files? Well, this is easy to do in the Bourne or Korn shells, but 4n the C-shell the way to achieve this is somewhat convoluted. So we will not look at it right now. You are referred to unit 4 on shell programming for this.

3.7.4 Filters snd Pipelines A filter is a command which can take its input from the standard input and can produce output on the stafidard output. Having the capability to read from or write to files is not a disqualification. So 1s is not a filter because it does not read from the standard input but cat is one because it cah do so (although it can read from a file as well) and also writes to the standard output.

You can think of B filter as a "device" placed between the standard input and the standard output which filters the standard input before placing it on the standard output. In the case of cat there is no filtering action at all, but a command like grep does perform some weeding action on its outpllt.

The standard output of a command can serve as the standard output of another. Several commands can bd chained together like this. Such an arrangement is called a pipeline. Pipclines are one of the big strengths of UNIX, because they often enable us to group several existing commands quickly to perform a task for which there is no command directly available.

A major design gwl of UNIX was to have an operating system which allowed easy sharing of data and progrms, and allowed people to build on the work of others instead of having to do things from sckatch. The facility of pipelining helps meet this goal because you can piece together commands written by different people to achieve your objective rather than wasting your time on doisg things which have already been done. Let us take a simple example.

Suppose you want to find out how many of the files in a directory are directories rather than ordinary files. It would have been wonderful if there were an option to 1s which did this job, but since that is npt the case we will have to try something else. One way is to look at the listing with Is -p and count lines which end in /. Such a visual method is tedious and prone to error especially if there are many files in the directory. So let us try to make UNIX do this for us. How about h e following?

% 1s -p qmp

% grep -t '$1 trnp

We rust get the listing in a temporary file tmp and then count the number of occurrences of / at the end of a linq in tmp using the grep command. The result will be available on the standard output. While this method will work it has a few disadvantages. One is that it is slow because an intermediate file has to be created. Secondly we cannot start the grep command before (he 1s finishes. Also if we run many commands like this we will be left with

Page 17: SPSA Unit-5 Part-2

temporary files which we will have to meticulously delete lest they clutter up our directory listing and otherwise waste disk space. So we can use a pipeline like this

% 1s -p I grep -c '$/' tmp

The 1 symbol is the pipe character. It means that the standard output of Is -p is passed to grcp. The act of connecting the standard output of a command to the standard input of another is also referred to as piping the output of the first command to the second. Here no temporary files need to be created or cleared up by the user as UNIX itself takes care of the details. Also the speed improves because the subsequent commands can s w a s soon as some data is available to them.

A command like 1s which does not take its input from the standard input can only be the first command in a pipeline. Similarly a command which does not write to the standard output can only be the last command in a pipeline. Also it is the user's responsibility to see that each command receives input in a form which i t c a ~ meaningfully transform, otherwise the results will be gibberish. Thus do not pass data files other than text files to grep because grep works only with text files. with lines delimited by tQe newline character.

Chcck Your Progress 9

1. Which of rhe commands you have learnt so far are filters?

2. How will you count thc numbcr of all filcs in a directory?

...................................................................................................................... 3. Look up the tcc command. How do you think it can be uscful?

3.8 PROCESSES

As you know, UNIX is a multi user, multi tasking opcrating system. This means that several I

users can work on a UNIX system at the same time. Also cach user can be performing more than one task, or process at a time. A process can be loosely thought of as a running program. Every process is thus a program but only progmms which arc running at a panicular instant are processes. Every instance of a running program is a process, so that a single program can be running as several processes in different states. Proccsscs have a life, they are creatcd, they run and finally terminate or die.

So far we have looked at processes running in the foreground. An example is the C-shell which you invoke on logging in. It enables you to run odicr processes and it prcsents you with the prompt every time a process terminates. Howcver such foreground or synchronous processing is not the only option you have.

You can run any program asynchronously, that is, in the background by terminating the command with an &. If you do so you are presented wilh the prompt immediatcly and you can then start another process, in the foreground or again in thc background. Bcforc that m X gives you a number called the process idcntificr, thc process-id or simply the pid. This is a numbcr you can use to find out about the statc of that proccss later on. Try

L'KIX - Getting

This gives you back the prompt but you might miss it as wcll as the process-id that UNIX displays because of the output which fills your screen. So running a command in the background does not affect its output. Also if you have only a fcw filcs in your directory this does not help you very much because the proccss ends vcry soon anyway.

Page 18: SPSA Unit-5 Part-2

USIX Operating So it makes sense to run a process in the background only whcn you cxpcct it to takc a long time to complete and want to do something else in the meantime. If you are going to gct output make sure it goes to a file othehvise it will be mixed up with the output of your background nrocess. So you can say

% 1s -lR / dirfile &

which will give you a complete directory long listing ofyour installation in dirfde. If you logout beforelbackground processes terminate they will all die but this can be prevented by saying nohupbcfore the command

B nohup 1s -1R /

This will send the output of the command to the default file nohup.out unless you have specified some other file to take the output.

% nohup Is -1R / dirfile

But this still leaves the nohup command vulnerable to disconnection by an interrupt, to prevent which you should give it in the background.

% nolbup Is -lR / dirfile &

Now even if you logout the process will continue until it terminates normally. Next time you login you can examine didile for your results. This is particularly useful if you are connected to your machine over a telephone line and are vulnerable to disconnections. Usually you would be well advised to redirect your standard error as well, so that even if your command fails for some reason you can examine the error messages it issued.

Beginners tend to go overboard with background processing because it is such a wonderful facility. While there is nothing wrong in experimenting and learning by trying out various things, you shoipld pay heed to some general rules when you are in a production environment. If you have started a process in the background and the output is going to a file, do not repeatedly examine the file t the exclusion of other activity.

% Is -@ / dirfile &

% tail -f dirfile

If you find yourself doing this you might have perhaps have run the Is command in the foreground. Runhing it in the background certainly has the advantage of being able to do something else anytime you wish, and your process is not vulnerable to inte~ruption by any accidental depresion of the DELETE key. Secondly do not run too many background processes because every process increases load on the system, and you must show consideration to bther users. Look up the nice command and use it to reduce the priority of lengthy processeS you run in Lhe background. Of course how many is too many depends on the machine and the other users. You should also make sure you do not set up race conditions or otherwise issuh a series of commands whose outcome depends on the time taken for execution. For exlamplc look at

% prog progfile &

% grep aity progfiIe grepfile &

If prog completes before you can issue the grep command, all is well. If prog does not produce any output bcforc the grep starts, grepfile will be empty. If the execution speed of prog is somewhere in between, the contents of grepfile will depend on this speed. So this is not a sequence of commands one should put in the background one alter the olhcr. Snrt ihe &rep only after the pros tcrminatcs or put the two in a pipcline. ,

3.8.1 Finclingout About Processes If you have run a command inathe background and want to know whelher it has completed or not you can use the ps command.

PID ?TY TIME CMD

1149 07 Q47 csh

Page 19: SPSA Unit-5 Part-2

1159 07 0: 02 Is

1168 07 o:@ cc

1276 07 0:01 PS

This means that you have three commands running at the moment. The csh is your login shell with process-id 1149 and started from terminal number 7. The command has used up 47 seconds of computer time. There are three other commands running and Is and cc are probably in the background. It is easy to see that ps is always one of the commands running. Thus one knows how many background processes one has set off, although some of the processes ps shows might have been created by commands you ran and not by you explicitly. This simple form of the ps command gives only the first word of your command but will show all your processes including those you might have started from some other terminal.

ps has quite a few options but we will look at only a few more. The -1 option gives more information on each process while the -f option gives the full command line including all arguments with which it was invoked. The -e option shows all running processes instead of just your own.

If you run ps and find that a process you started in the background is no longer listed, it means that the process has completed or that it aborted for some reason. Also remember that ,ps gives a snapshot of the state of processes at some time, and that by the time the output is displayed on the terminal matters might have changed.

3.8.2 Stopping Background Processes You know that a foreground process can be terminated by pressing the DELETE key. But this will naturally not work for a process running in the background. To stop such a process you need to know its pid, which you might have noted while invoking the command or can deduce by examining the listing produced by ps. Then just say

% kill 1168

and that process will be stopped. If a process has created other child processes, you need to find out their process-ids using ps and then give them all as arguments to kill. Processes can be killed by passing them various signals with numbers 1 to 15. If nothing is specified then 15 is the default signal number used by kill. ~ d t h e command above is the same as saying

% kill -15 1168

If you have many processes running and are desperate because you cannot find out the process-ids, you can kill them all except your login shell by saying

% kill 0

Some commands are written such that they can catch signals and act in a predetermined manner on receiving them rather than executing the default action of terminating the process. The login shell is such a command. So

% kill 1149

has no effect. Such processes can be killed with signal number 9, which cannot be caught sr ignored. But

% kill -9 1149

will kill your login shell itself and you will be back at the bgin prompt.

Check Your Progress LO F. Can you kill the ps command?

...................................................................................................................... . .

2.' Try killing somebody else's process.

3. Can you kill your own login shell from anothcr terminal?

Page 20: SPSA Unit-5 Part-2

USJX Operating System-I ...................................................................................................................... ..

3.9 SUMMARY

In this unit we have started at the beginning and looked at many basic UNIX commands. However thee are many useful commands we have not been able to examine. You must refer to the manual and learn these. You should now be knowing enough about UNIX to conduct a session with ease. In the next unit we will examine various types of editors in slight detail.

3.10 MODEL ANSWERS

Check Your Rrogress 1 1. The contents of the directory, which is the files that are in it and perhaps some that have

been in it, are seen on the screen.

2. No model answer.

3. The file gets typed slower or faster than usual. At a setting of say 75 baud, the characters appear labriously on the terminal.

4. No model answer.

Check Your Progress 2 1. The directory heavens has hidden files, that i<$les that begin with *.' character. Since it

is not empty. the directory does not get removed.

2. No model answer.

3. No model mswer.

Check Your Wogress 3 1. No model mswer.

2. You cannot execute the directory in either case and will get an error message.

3. No. This is~because of the definition of search permission.

4. Yes, you only need write peimission on the directory. It does not matter whether you can write to the files or not

Clreck Your Prbgress 4 1. No model mswer.

2. Nomodelanswer.

3. No model answer.

4. No model aOswer.

5. No model answer.

Check Your kqgress 5 1. No model answer.

2. No model arhswer.

Check Your kagress 6 1. No model wswer.

Page 21: SPSA Unit-5 Part-2

2. No model answer.

Check Your Progress 7 1. You lose catfile because it gets truncated to zero bytes. The shell tries to create a file

called catfile, and because it already exists, simply truncates it. Thus, cat has an empty file to cat and does nothing.

Check Your Progress 8

1. A file catfile can be created from the terminal by saying

% cat catfile

Now type in the desired contents and terminate the process with an end of file character ("D) on a line by itself.

You cannot edit or alter a file directly by this method. You can only enter the text of the file all over again. You can also make catfile identical to some other existing file herefile by

% cat herefile catfile

This is like saying

% cp herefile catfile

Check Your Progress 9

1. No model answer.

% 1s 1 wc -1

3. No model andwer.

Check Your Progress 10 1. This is not possible theoretically but very difficult to achieve in practice. By the time

you have issued the kill command, the ps would have terminated anyway.

2. You will get an error message saying

Permission denied

You may kill only your own processes. Only the super user can kill anybody's processes.

3: Yes, this can be done.

UNIX -