.bp
.ds F1 - % -
.ds Fd
.ds F3  ~
.ds Fl  Unit~I
.ds Fr  Module~III
.ds H1  ~
.ds Hl MP119
.ds Hr Introduction to UNIX
.PH "Module~III---file manipulation" 5 2 2 3
.PP 5
This module covers Unit I objectives 5,6,7,8,9 and 10.
.sp 2
.PH "OBJECTIVES"
.sp
.PP
Upon completion of this module, you will be able to both state how
to, and to:
.sp
.L1 5 2 1
Create text files using the CAT command.
.L1
Display files at the terminal.
.L1
Copy files.
.L1
List the names of existing files.
.L1
Delete files.
.L1
Obtain printed copies of files.
.L1
Compare files.
.L1
Change the mode of files.
.E1
.bp
.PH "What is a file?"
.PP
A file is a collection of information stored by you, the user, in
the system. That is, a file contains whatever information you place in it.
It consists of any number of lines, each of which is concluded or delimited
by the depression of the RETURN key. A file may contain an unlimited
number of lines; it could be a letter, a memo, portions of a manual, etc.
UNIX doesn't require that you use any particular structure or design;
it has by far the easiest and simplest method of creating files.
.PP
Files are named by sequences of 14 or fewer characters.  Any
valid character may be used in upper or lower case. Filenames are
arbitrarily chosen. However, it is sometimes easier to remember the
name of the file or the type of information stored in the file if you
use symbolic names; i.e., let the name indicate the kind of file it is.
.PP
You may create an unlimited number of files, which are kept
in a directory assigned to you by the system.
.PP
The system assigns each user a directory, called a login
directory.  A directory is just another type of file and will be
discussed in detail in Unit II.
.PP
For now, let's see if we can get a good grasp on the concept
of files by the following analogy.
Imagine the file structure as being a library.  You have your
own private book shelf (directory) in which you keep all your books
(files).  Got it? Good. Now each book on the shelf must have a different
title (name). This applies only to individual users, that is, someone else
could have a book with the same title as you, and it would be perfectly
all right.
.ne 10
.PP
The manipulation of files is where you will really get to see
some of the power and sophistication of UNIX.  You'll see that when we
create a file. First, though, let's review what we've just covered
about files in general.
.bp
.PH "EXERCISES"
Answer the following true-false questions:
.L1 5 2 1
Only certain kinds of information may be placed in a file.
.L1
The maximum number of characters a filename can have is 14.
.L1
A file may contain a maximum of 14 lines.
.L1
A line is concluded (delimited) by depressing the RETURN KEY.
.L1
You can give one of your files the same filename
as that given to one of his/her files by another user.
.L1
You can create an unlimited number of files.
.E1
.bp
.PH "Answers"
.nf
1. F     4. T

2. T     5. T

3. F     6. T
.fi
.PP
I'm sure you had no trouble with these questions. Now, let's turn to
the task of creating files.
.PH "Creating Files"
.PP
UNIX provides several methods which can be used in creating
a file.  This section discusses how this can be accomplished using the
"cat" (conCATenation) command. (The other methods will be discussed
later in the course.) In case you're interested, concatenation means
the act of linking together. As used here, it indicates that certain
information is linked together to form a file.
.PP
The "cat" command is an extremely versatile command. It can be used to
create, display, combine and copy files. You may create a file by typing:
.sp
.in 20
% cat > filename
.br
<information to be stored in file>
.br
<ctrl-d>
.br
.in -20
.PP
"Cat" is the name of the command; ">" is called a divert
and means to write the information from the program or command on the left
of ">" into the file on the right of ">."  Since no file is specified to the
left of ">," the system places whatever you type into the file on the
right of the ">."
Example:
.sp
.in 20
% cat > chap1
.sp
<now type in whatever text you want>
.sp
<ctrl-d> signals end of text
.sp
%
.in -20
.PP
This creates a file called chap1 which will remain in your
directory until you delete it. The command "ctrl-d" signals the end of
text for the file, and causes the (%) to be displayed indicating that the
system is ready to accept another command.
.sp
.ne 5
.in 6
.ti -6
Note: When you are creating a file, corrections may be made
using the correction characters.
.in -6
.PH "Copying Files"
.PP
The "cat" command is used to copy the contents of one file into
another file by specifying a file on the left of the ">".  Suppose the
following command is issued:
.sp
.ti 20
%cat file1  >  file2
.ne 5
.PP
You would now have two identical files.  The above
command will cause the system to read from "file1" and place what
it reads into "file2"; thereby creating two identical files with
different names.
.PH "~~~~~~~~~~~~~~~Displaying Files"
.PH "Cat~command"
.PP
How would like to see your creation or maybe show it off to the
boss?  You can by using this form of the "cat" command:
.sp
.ti 20
% cat chap1
.PP
The above form of "cat" is used to display the contents of existing
files.  The contents of the file will be displayed in a continuous
stream which makes it somewhat difficult to read.
.PP
As a remedy for this situation, you may use the following:
.sp
.ti 20
% cat chap1 | br
.sp
where "cat" and "chap1" still have their previous meaning; "|", the
upper-case backward slash, is referred to as a pipe.  This causes the
system to route your output through another program (br).
The "br" program is the browse program that is used to cause a pause
after each page of output. The "br" now acts as a filter and
may be used with any other command which displays information
on the terminal. This command works on both the Superbee and Delta
Data terminals.
.sp
.in 10
.ti -10
Notes: (1)The br program displays one page of output at a time.
It doesn't automatically display one page after another. You will
have to depress the RETURN key to view each succeeding page.
The browse program is designed for all standard terminals.
~~~~~~~(2)It is possible to use "br" in a manner different from that
specified above. The command:
.sp
.ti +10
%br chap1
.sp
will do the same thing as:
.sp
.ti +10
%cat chap1 | br
.sp
and save you some time typing.
.in -10
.PH "The Print Command"
.PP
The "pr" command is used to display files also.  Wait a minute,
don't skip over this just because you already know how to display files using
the "Cat" command. This command produces formatted printouts of your files
such as: headings with the date, time, page number and file name at the
top of each page.
.PP
Several other options are available. Following is the full
form of the command, with the options included:
.sp
.ne 10
.ti 15
pr [-h (header)] [n] [-t] [-m] [-n] filename
.sp
The options have the following meaning:
.sp
.ul
OPTION~~~~~~~MEANING"
.in 12
.sp 2
.ti -12
-h~~~~~~~~~~This allows you to specify a header of your
choice to be printed on the header line
instead of the file name, for instance:
.sp
.ti +10
pr -h SECRET chap1
.sp
will cause the file chap1 to be displayed
and will produce the following heading on
each displayed page:
.sp
.ti +10
Feb 28 07:57 1978 secret page 1
.br
instead of:
.br
.ti +10
Feb 28 07:57 1978 chap1 page 1
.sp
If the header consists of more than one word,
it must be enclosed in quotation marks. As
you see, this can be used to place a class
ification on your output. Let's look at the
meanings of the other options:
.sp 2
.ti -12
-p~~~~~~~~~~Begin printing with the page number n, as
.sp
.ti +10
pr -p3 chap1
.sp
The first page of your output will be
numbered 3 instead of 1.
.sp 2
.ti -12
-t~~~~~~~~~~Do not print the header normally printed
on each page, for example:
.sp
.ti +10
pr -t chap1
.sp
will produce output similar to that
obtained  using the "Cat" command.
.ne 12
.sp 2
.ti -12
-m~~~~~~~~~~Since more than 1 file may be specified in
the "pr" command, this gives you the option of
having all the specified files displayed on
the same page, side by side; e.g.:
.sp
.ti +10
pr -m chap1 junk
.sp
will display both files, chap1 and junk, with
formatted headers.
.sp
.ti -12
-n~~~~~~~~~~The system will number each line of your
text if you specify this option. It looks like this:
.sp
.ti +10
pr -n junk
.sp
and the output will appear as follows, assuming
junk contains the following indicated text.
.sp
.in +5
1~~~~~~~~~~~~Now is the time
.br
2~~~~~~~~~~~~for all good men
.br
3~~~~~~~~~~~~to come to the aid
.br
4~~~~~~~~~~~~|
.br
5~~~~~~~~~~~~|
.br
6~~~~~~~~~~~~|
.br
.in -5
.sp
Each line, including blank lines, is sequentially
numbered.
.sp
.in 7
.ti -7
Note:~~Any of these options may be combined; however,
it isn't required that you specify any of them.
The pr command in its simplest form is:
.in -7
.sp
.ti +25
pr chap1
.sp
.in 7
The "pr" command can be used as a filter also as
shown below:
.sp
.ti +15
cat chap1|pr
.sp
.ti +10
or:
.ti +15
cat chap1|pr -h chap1
.sp
.in 7
.ti -7
Note:~~When pr is used as a filter, the filename is not
automatically printed in the header line.
.in -7
.PH "EXERCISES"
.PP
Let's have a quick review before we move on. Answer the following
questions.
.L1 5 2 1
In the space below print (with correct spacing) what
you would type to create a file.
.sp
.L1
Suppose you want to copy the contents of "file2" into
"file4" print what would follow "%" below:
.sp
.ti 20
%
.L1
Assume you are going to read a file. What is the difference
between the following commands?
.L2
%cat chap3
.L2
%cat chap3 | br
.L2
%br chap3
.E2
.L1
What does the following command do?
.ti 20
.sp
%pr -pn chap1
.E1
.sp 2
Check your answers on the following page.
.bp
.PH "Answers:"
.L1 5 2 1
% cat > filename
.br
<information to be stored>
.br
<ctrl-d>
.sp
Note:  You wouldn't type the "%." It is there to
illustrate the process.
.L1
cat file2 > file4 (Remember -- the spacing must be
as shown.)
.L1
The first command means that everything in Chapter 3
will be displayed as a continuous stream.
The second command (%cat chap3 | br) displays Chapter 3
a page at a time. (Don't forget, you have to hit the
RETURN key to display the next page.) The third command
(%br chap3) will do the same as the second.
.L1
It will begin displaying the file with the page number
"n"
.ti +15
For example:
.sp
.ti +15
%pr -p88 chap3
.sp
will cause chapter 3 to be displayed, beginning with
page number 88. Now, don't get confused. This does NOT
mean that the first 87 pages of Chapter 3 will be omitted.
All the chapter is displayed and the first page on the
chapter is given page number 88.
.E1
.PH "Off~Line~Print~(opr)"
.PP
As soon as you have your file as you would like it to be, I'm sure you
will want to obtain printed copies in order to distribute the information
to other people. This is achieved by using the "Off Line Print" command.
It has the form:
.sp
.ti 20
%opr <filename>
.ti 20
Example:% opr chap1
.sp
After a short pause, the system will display the prompt "%." This
lets you know that your file has been sent to the printer. If the system
is heavily loaded it might take some time for it to return the prompt.
You can speed things up by typing "&" immediately after the filename.
This puts the job in background, immediately returning the job ID number
and the prompt. You can now work on something else while the system performs
your job.(If you plan to logout while a background job is being performed
type "detach" not "logout" or else the job will be terminated.)
Just where printer (or printers) for your system is located can be determined
by checking with your system manager.
.sp
.in 9
.ti -9
Note: 1. If your system has more than one printer, and you
wish to send your output to a specific facility,
you will have to give more information. For example,
on the ELROND computer, you must state
the number of the remote printer as follows:
.br
.ti +15
opr -p1 junk
.br
Where "1" is the number of the remote printer, and "junk"
is the file being printed.  Check with your operations
people to find out the specifics for your system.
If you don't specify -p1 the system will print the job on
the "main" printer.
.sp
.ti -9
~~~~~~2. Files being sent to the printer should not contain more
than 2,000 lines. If your file is larger, it will have
to be divided into smaller files. (See Split Command.)
.sp
~~~~~~3  The job ID number returned with the prompt in background
jobs is significent. If you want to abort the job before it reaches the
printer just type "kill" and the job ID number. Also, some operators
will not give you your listing unless you specify the job number.
.sp
~~~~~~4  If you are going to print a classified job or document you
must specify this. For example:
.sp
.ti +10
opr -c "Hush Hush" junk
.sp
will mark the printout of junk with the classification Hush Hush.
(The classification is enclosed in quotes because of the space between
the words.)
.in -9
.PH "The Opr~Command~as~a~Filter"
.PP
The "opr" command can also be used as a filter. Some other
command may be first applied to your file for formatting purposes,
then the results of that command is routed to the "opr" program to
be printed by the "opr" command, as shown below:
.sp
.ti 20
pr chap1|opr
.sp
.ti 15
or:
.sp
.ti 20
cat chap1|opr
.sp
.ne 15
.PH "Concatenating~Files"
.PP
Files can be concatenated or combined by using the "cat"
command. Using "cat" in the following form:
.sp
.ti 20
cat file1 file2 file3
.sp
causes the system to concatenate the three files and then
display them. As you can see, this is a shorthand method of
displaying three files; the command is only issued once. The
above command is equivalent to:
.sp
.in 20
.ne 3
%cat file1
.br
%cat file2
.br
%cat file3
.sp
.in -20
When the above form is used, the system displays each file,
one at a time, with a prompt after each command. It may be
advantageous to create a permanent file that is composed of
the several files. The following command accomplishes this:
.sp
.ti 20
%cat file1 file2 file3  > file4
.sp
This directs the system to write the several files into "file4,"
thus causing them to exist as long as "file4" does.
.PP
Files can be concatenated in the manner described above and then
piped through the opr program to obtain printed output. It should be
noted, however, that this procedure will cause any header lines in the
files to be suppressed.
.sp
.in 8
.ti -8
Note:   When used in this context, the same file name cannot appear
both to the right and to the left of ">."
.PH "Appending Information"
.PP
Information contained in one file may be appended to the
information contained in another file by using:
.sp
.ti 20
% cat file1 >> file2
.sp
This will append "file1" to "file2."
.PP
How can you use this command to cause the information you type at the
terminal to be appended to "file2" without first placing it into a file?
Answer in the space provided.
.sp 2
.ne 15
Is your answer:    % cat >> file2? If it is, wonderful! You have
mastered the "cat" command. Our answer was derived from the following
deduction. Recall the section on creating a file. In that example no
file was specified to the left of the ">" and the system treated
the input from the terminal as a file. Likewise, what you type will
be appended to "file2," since no file has been specified to the left
of the ">."
.sp
Ready to try wor                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                by making it a copy of junk2; display junk4.
.L1
Append junk1 to junk4; display junk4.
.L1
Concatenate both junk1 and junk2 and send it to your favorite
line printer.
.E1
.sp 2
.in 5
.ti -5
*****If you cannot perform all of the above exercises, please
review the "cat" command and then repeat the exercises.
.in -5
.bp
.PH "Filenames and Wild Cards"
.PP
It was established in the last section that filenames should
not exceed 14 characters.  Not that you would get an error, it's
just that the system ignores all excess characters.
In naming files, certain conventions are usually observed so
the nature of the file can readily be discerned from its name. For
instance, suppose your directory contained a book where each file
represents a chapter; you might name the files:
.in 25
chap01
.br
~~|
.br
chap02
.br
~~|
.br
chap20
.in -25
Maybe your directory consists of chapters from a book, where each file
represents a page;
you might name the files:
.in 25
pageI
.br
~~|
.br
pageII
.br
~~|
.br
pageXXV
.in -25
.sp
You will notice that the file names in each group are identical except
for the suffixes.
.PP
The advantage in using this approach in naming your files is the ease
and flexibility it affords in manipulating your files.  This flexibility
is made possible by the use of "wild cards."
"Wild cards" are special characters which may be used as prefixes or
suffixes to filenames. They allow the same action to be performed on many
files by a single command.
.PP
The "wild card" characters are:
.sp
.in 10
.ti -10
"*"~~~~~~~Matches any string of characters.  Thus "*" alone
matches all filenames in your directory.
.sp
.ti +5
Example:   % cat *
.sp
will display all files in your directory.
.sp
.ti +5
Example:   % cat chap*
.sp
will display all files beginning with "chap."
.sp
.ne 5
.ti +5
Example:   % cat *chap*
.sp
.ne 10
will display all files containing "chap" anywhere
in the name.
.sp
Answer this question in the space below.
%cat *chap --- will display which files?
.sp 2
If you said all files ending in chap,
good. Otherwise, review the beginning of
this section.
.sp
.ti -10
"?"~~~~~~~Matches any single character; thus "?" alone refers
to filenames consisting of one character.
.sp
.ti +15
Example %cat ?
.sp
will display all files having exactly one character for
its name.
.sp
Here is a question for you. Be careful, it's a bit
tricky.
.sp
.ti +5
%cat chap? --------- would display which files?
.sp
If your answer is all files with names 5 characters
long beginning with chap, very good. For example, if
if you had files chap1 through chap16, the files
chap1 through  chap9 would be displayed.
.sp
.ti -10
[...]~~~~~"[...]" means to match any of the characters inside
the brackets.  Thus, "[xyz]" means to match any one of
the characters:  "x," "y," or "z."
"[a-g]" also means to match any single character from
"a" through "g."
.sp
Examples:
.sp
.ti +5
% cat chap[a-c]     and     % cat chap[abc]
.sp
will display files, "chapa", "chapb", and
"chapc" if they exist. However, no error is generated
if they don't.
.sp
Which files would be displayed by this?
.sp
.ti +15
% cat chap[12345]
.sp 2
You're correct, if you answered all files beginning
in chap and ending in 1,2,3,4 or 5.
.in -10
.ne 15
.in 9
.ti -9
Note: 1. Wild cards are used only in referring to existing files, and
can not be used in creating new files.
.br
.ti -9
~~~~~~2. Any of the "wild cards" may be combined.
.br
.ti -9
~~~~~~3. Of these niceties, the "*" is the most useful, and you should
use it until you become confident in its use.
.br
.ti -9
~~~~~~4. Wild card expressions are typed solid; no embedded spaces
are permitted.
.in -9
.sp
Okay, for a rating of excellent, answer this one correctly:
Which files will be displayed by:  %cat *[a-z] ?
.sp 2
The answer is: all files ending in one of the characters "a" thru "z."
.PP
What we did was to combine two "wild card" characters, the "*" which means
all files beginning in anything and the "[a-z]" which means any file ending
in one of the 26 alphabetic characters.
.sp 2
SPECIAL HINT:  Always, but always, answer the questions we ask before
looking at the answer.  You'll learn much, much more.
.sp 2
.PH "Listing~Filenames"
.PP
The files you have created since completing the last module
were placed into your login directory by the system.  You are probably
wondering how you will ever be able to remember the names of these files,
so you won't have to keep referring to some ledger.  Well, trouble yourself
no longer, for in addition to placing your files in a directory, the system
also places the names of your files on a list similar to a table of contents.
.PP
You may readily gain access by using the list command which has
the form:
.ti 20
ls <option>
.sp
where <option> may be -l, -t, -r, "wild cards" and possible file names.
Assume your directory consist of files: chap.1, chap.2, junk3, and temp4.
.ne 10
The command:
.ti 20
% ls
.sp
will produce this list of all files in your directory.
.sp
.in 20
chap.1
.br
chap.2
.br
junk3
.br
temp4
.in -20
.sp
Note that list is automatically sorted in alphabetical order.
.sp
.ti 20
ls -t
.sp
.ne 10
The command "ls -t" will list the filenames in the order in which
they were created or changed (last, first).  This command:
.sp
.ti 20
ls -r
.sp
will list the filenames in descending order, while
.sp
.ti 20
ls -l
.sp
produces some very pertinent information about the file, not
just its name. It is also the most frequently used of the options. It
will produce something similar to this:
.sp
.ti 10
-rwx-rw-rw 1 mmw 128 Feb 21 12:05 junk
.sp
The "-rwx-rw-rw" tells who has permission to read, write, or execute the file
This topic is discussed later in this module.  The "1" indicates how many
copies (or links) of the file exist. The "mmw"
is the login name of the "owner" of the file --- the person who  created it.
"128" is the number of characters in the file. "Feb 21 12:05" is the date and
time the file was created or the last time the file was modified.  "junk" is
the name of the file.  I think you can see why "ls -l" is the
option used most often.
.sp
.in 9
.ti -9
Note: 1. Options may be combined: "ls -lt" would produce the
same thing as "ls -l," but would be sorted to show
the order in which the files were changed.
.br
.ti -9
~~~~~~2. You can also specify the files you're interested in,
and ls will list the information about them only.
.ti +15
Example:  ls -l junk
.br
will produce one line of information pertaining to
the file named junk.
.br
.ti -9
~~~~~~3. As you saw in the last section, "wild card" expressions
may be substituted for filenames.  Thus, "wild card"
expressions may also be used in this command.  To
illustrate, suppose you wish to determine which files
exist in your directory that have ".g" as the ending.
The following command could be used:
.br
.ti +20
ls *.g
.br
.ti -9
~~~~~~4. If you list all the files in your directory, you may
notice the names of some files you didn't create--these
have been put in your directory by Unix.
.br
.ti -9
~~~~~~5. "lsm" is a version of 'ls' which places the filenames in
rows on the terminal instead of in one long column.
.in -9
.sp
.ne 15
Let's practice listing filenames.  Do the following exercises.
.PH "EXERCISES"
.sp
.L1 5 2 1
Use the list command to determine which files are in your
directory (display names only).
.L1
Do #1 again, except have the names appear in descending order.
.L1
List all information pertaining to your files, not just names, in descending
order.
.L1
List all files whose name begins in 'junk' followed by any single character.
.L1
Repeat any exercises that gave you difficulty.
.E1
.bp
.PH "Deleting Files"
.PP
Once you have no further use of a file it can be deleted from your
directory by using the "Remove Command" which has the following form:
.sp
.ti 22
rm <filename>
.sp
.ti 19
Example: rm junk
.sp
will delete the file "junk" from your directory.
.sp
.PH "Deleting Several Files"
.PP
Unlike some other systems which limit their users to the tedious
task of issuing the same command several times in order to delete several
files UNIX allows you to accomplish this feat by a single command:
.sp
.ti 12
% rm file1 file2 file3 ...  file'n'
.sp
Of course "wild card" expressions can be used to
simplify the command.
.sp
Example:
.sp
.in 12
.ti -12
% rm chap*  Will delete all files beginning in "chap."
Since a "wild card" is being used in the "Remove"
command, it could result in the deletion of
several files.  As a precaution, the system will
ask you to confirm the deletions by displaying:
glob[confirm].  You will enter a "y" if you still
want these files deleted.  Otherwise, the command
will be ignored.
.ne 15
.sp
Here is a question to check your understanding.
Which files would this command delete?
.sp
.ti +15
% rm *
.sp 2
You're right if you said all of your files will be deleted.
.sp
.ti -12
Caution:~~~~Before deleting a file, be certain that it is a file you no
longer need. However, don't become over cautious and,
like the proverbial "string saver" keep everything.
.in -12
.bp
.PH "Comparing Files"
.sp
.PP
Unix allows you to compare files for similarities or
differences.  The following two commands are used for
this purpose.
.sp
.L1
.I "cmp"
.sp
.in 8
.ti -4
----This command compares two files for similarities. No
response is made if the files are identical.  If they
differ, the system displays the position number of the
character and the line number at which the difference
occurred. The form of the command is :
.sp
.ti +15
cmp <file1> <file2>
.sp
.ti +12
Example: cmp chapt1 chapt2
.sp
In response, the system would display something similar to this:
.sp
.ti +8
chapt1 chapt2 differ: char 5, line 1
.bp
.L1
.I "diff"
.sp
.ti -4
----This command is very similar to the "cmp" command.
It also locates differing lines in comparing files.
Its form is:
.sp
.ti +13
diff <file1> <file2>
.sp
.ti +4
Example: diff chapt1 chapt2
.sp
In this case, the system will compare "chapt1"
with "chapt2." If the files are not identical, the
line numbers and the statements that differ in
both files will be displayed.
.sp
.in -8
.in 20
.ti -10
response: 1,5c1,9
.br
<
.br
<  <lines that differ in file1>
.br
<
.br
------
.br
>
.br
>  <lines that differ in file2>
.br
>
.in -20
.sp
.in 7
.ti -7
Note:~~If the lines that differ are scattered throughout
the files, then you will see several of the above
responses --- one each time another line is
encountered in file 1 that differs from file 2.
"1,5c1,9" indicates the line numbers of the statements
that differ; "1,5" refers to file 1, and "1,9"
refers to file 2, ie. lines 1-5 of file 1 differ from lines
1-9 of file 2. This really refers to the type of commands
that one would use in the text editor to modify one file
so as to make it into another.
.E1
.bp
.fi
.PH "Changing File Modes"
.sp 3
.PH " Access Privileges"
.PP
Every person who uses the  system has two identification
names --- a user identification which is your login name, and a
group identification which is the designator of the group  in which
you are assigned, for example:  E53 or R43.
.PP
When a file is created the system assigns specific access
privileges to the owner (you), the owner's group, and all
other users.
.PP
There are three access privileges associated with a file.
The permission to read, to write, or to execute a file may
be granted or denied a user.  Therefore we refer to these
capabilities as privileges.
.PP
Now, let's explain what is meant by the above.  To read
a file means being able to display or to copy a file; to
write a file means being able to delete, to change or to
modify a file; to execute a file refers to the execution
of an object file; If you don't understand what "execute a file"
means, don't worry about it.  You will have no
need to use this privilege during this course.
.PP
These privileges are given to other users by you, the owner.
This affords some means of security protection for your
file as you determine who has access, as well as the sort of
access others have to your file.
.sp
.PH "chmod~Command"
.PP
When the file is initially created, the owner has read
and write privileges, and all other users have only the
read privilege.  We refer to the privileges assigned as
.ne 10
the mode of the file.  Now, in order to change the mode
of a file, you would use the following command:
.sp
.ti 15
chmod   [-id] <mode> <filename>
.bp
.PP
Whether or not the -id option is used depends upon just how many accesses
you have to change. If you only plan to change the privileges for one
category of users, you might use the -id option, which identifies the
users to whom the access privileges are given:
.sp
.I "~~~~~~~~Id~~~~~~~~~~~~~~refers~to:"
.sp
.in 8
o~~~~~~~~~~~~~~~~owner
.br
g~~~~~~~~~~~~~~~~group
.br
a~~~~~~~~~~~~~~~~all users (owner, group, other users)
.br
p~~~~~~~~~~~~~~~~public (other users)
.sp
.in -8
Note: Only the o, g, a, or p is specified.
.PP
The number designation for the various access modes depends on how
the chmod command is issued. If the -id option is used, the mode is
a single digit. If the command is issued without a -o, -g -a, or
-p, then the numbers of the mode range from octal 000 to 777.
.sp
.I "~~~~~~~Mode~~~~~~~~~~~~~~~~~~Meaning--Used with the -id option"
.in 8
0~~~~~~~~~~~~~~~~No access
.br
1~~~~~~~~~~~~~~~~Execute access
.br
2~~~~~~~~~~~~~~~~Write access
.br
3~~~~~~~~~~~~~~~~Execute and write access
.br
4~~~~~~~~~~~~~~~~Read access
.br
5~~~~~~~~~~~~~~~~Read and execute access
.br
6~~~~~~~~~~~~~~~~Read and write access
.br
7~~~~~~~~~~~~~~~~Read, write, and execute access
.in -8
.sp 2
.I "~~~~~~~Mode~~~~~~~~~~~~~~~~~~Meaning--Used without -id option"
.in 8
400~~~~~~~~~~~~~~Readable by owner
.br
200~~~~~~~~~~~~~~Writable by owner
.br
100~~~~~~~~~~~~~~Executable by owner
.br
~40~~~~~~~~~~~~~~Readable by owner's group
.br
~20~~~~~~~~~~~~~~Writable by owner's group
.br
~10~~~~~~~~~~~~~~Executable by owner's group
.br
~~4~~~~~~~~~~~~~~Readable by all users
.br
~~2~~~~~~~~~~~~~~Writable by all users
.br
~~1~~~~~~~~~~~~~~Executable by all users
.in -8
.bp
.PH "Assigning the Mode"
.PP
First determine which of the three privileges you
wish to assign to yourself, your group, and all others.
Now decide which form of the command you wish to use--with or
without the -id option.  Although the command issued without the -id option
seems more complicated, it does have its advantages.  It is unlike the
chmod -id command, where
the privileges for the different individuals must be
assigned in separate commands.  Privileges for all users, and all combinations
of access can be assigned in one command, by adding the numbers of the
of the desired access modes.
For example, suppose you want
to set the access codes on your file, chap1, so that it is readable and
writable for the owner, as well as for the owner's group.  The command
would be:   chmod 660 chap1.  Why 660?  400 (owner readable) +200 (owner
writable) +40 (group readable) +20 (group writable).  This would have taken
two separate commands with the -id option.  Here is another example,
suppose you wanted to make the file readable, writable, and executable
by all users, either of the following commands would do it:
.sp
.ti 15
% chmod -a7 chap1   or % chmod 777 chap1.
.sp
.in 7
.ti -7
Note:  DO NOT space between the <-id> and the <mode>.
Also, if the <-id> is accidently left unspecified, then
the mode will take on very different values, e.g.:
.sp
.ti +15
% chmod 7 junk
.sp
will give  read, write, and execute privileges
to other users but no access to yourself.
This may be inadvisable for sensitive files.
.sp
Whereas:
.sp
.ti +15
% chmod -g7  junk
.sp
will give only the owner's group, read, write, and
execute privileges without destroying the assigned
privileges of the other users.
.in -7
.sp
.in 6
.ti -6
Note: The previous example demonstrates just what kind of trouble can result
from mixing up the form of the chmod command.  Be careful when you
change the mode of access privileges! Use the ls to check privlidges after
using the chmod command.
.in -6
.bp
.PH "Determining File Privileges"
.PP
To determine which privileges are currently assigned,
use this form of the "List" command:
.sp
.ti 25
ls -l
.sp
which produces something similar to:
.sp
.ti 25
-rwxr-xr--
.PP
This is the only portion of the line produced from the
list command that is of interest at this time.
.PP
The  first "-" indicates that this is a file. If it were
not a file, it would be a directory and a "d" would appear
here.  The next three characters represent the owner's
privileges ( read, write, and execute), the next three
characters represent the owner's group privileges ( read,
and execute), and the last three characters represent the
privileges shared by all other users (read).
.PP
Okay, try this: write the command to assign the read only
privilege to all users of the 'junk' file.
.sp 2
Answer: % chmod -a4 junk
.PP
If this is also your answer --- very good.  You may
continue to the exercises, otherwise please review
this section. The system normally assigns a "default"
permission to each file it creates. This should be mode 750
(rwxr_x___) or 640 (rw_r_____). This is to protect you from
having your files accidently "read" by snoopers or unfriendly
people. If you wish to share a file with someone, you may have to
change the mode of the file. Remember, however, that if the "sharer"
can read it so can other people.
.ne 35
.PH "Exercises"
.sp
.L1 5 2 1
Determine which privileges have been assigned to
you, your group, and other users for one of your
files.
.L1
Change the mode to reflect the following:
.L2
You, the owner, have read and execute
privileges.
.L2
Your group has read and write privileges.
.L2
All other users have the read only privilege.
.E2
.L1
Verify that the changes were made.
.L1
Reassign the original privileges.                  .
.L1
Practice any procedure you are unsure of.
.E1
.sp 2
This concludes the instructional sequence for Module III.  Refer to
module objectives and decide whether you can do what is required.
Review as needed, and then take the Module Test on the following page.
.bp
.PH "~~~~~~~~~~~~~~~~Module III Test"
Directions:~Answer the following questions without aids
of any kind. Minimum passing score is 9 out
12 correct.
.sp
.L1 5 2 2
The ----------- command is used to create a file.
.L1
The command: % cat junk, will:
.L2
create the file, junk.
.L2
display the file, junk
.L2
delete the file, junk.
.E2
.L1
The command:  % cat j1 > j2, will:
.L2
copy j2 into j1.
.L2
copy j1 into j2.
.L2
concatenate j1 to j2.
.E2
.L1
-------------- is the command which could be used
to concatenate two files (j1 and j2) to form the
a file named "temp."
.L1
What does the command: % cat j1 >> j2 , do?
__________________________________________
.L1
The __________ command is used to place headings,
page numbers, etc. in your output.
.L1
Assume you are using the "pr" command to output the
file "junk."  Write the command to suppress the
heading.
.L1
Write the command which could be used to obtain a line
printer listing (paper) of the table of contents for your
directory.
.L1
Write the command used to delete all files beginning
in "junk" from your directory._______________________
.L1
Write the command used to display any file beginning
in "page" and ending in 1, 2, 3, or 4. ______________
.L1
Write the command used to compare two files, "junk1"
and "junk2," to determine how they differ.
______________________________
.L1
Write the command used to give all users the read,
write, and execute privileges with the "junk" file.
.E1
.bp
.PH "~~~~~~~~~~Answers to Module III test"
.L1
The
.I "cat"
command is used to create a file.
.L1
The command: % cat junk, will
.I display~the~file,~junk.
.L1
The command, % cat j1 > j2, will
.I copy~the~file~j1~into~j2.
.L1
.I %~cat~j1~j2~>~temp
is the command used to concatenate
j1 and j2 to form the file, temp.
.L1
The command, %cat j1 >> j2,
.I appends~j1~to~the~end~of~j2.
.L1
The
.I pr
command is used to place headings, page
numbers, etc. in your output.
.L1
.I %~pr~-t~junk
is the command used to suppress the headings.
.L1
.I %~ls~-l|opr
will produce a listing of the table of
contents for your directory.
.L1
.I %~rm~junk*
will delete all files begining in "junk"
from your directory.
.L1
.I %cat~page[1234]~or~%~cat~page~[1-4]
will display any
file in your directory begining in "page" and ending in
1,2,3,or 4.
.L1
.I %~diff~junk1~junk2
is the command used to determine
how "junk1" and "junk2" differ.
.L1
.I %~chmod~-a7~junk~or~%~chmod~777~junk
is the command
used to give all users the read, write and execute
privlidges for the file "junk."
.E1
.sp 2
.ne 3
If you have answered more than 3 questions incorrectly
please review this module.
.fi
