.bp
.af % 1
.ds F1 - % -
.ds Fd
.ds H1  ~
.ds Hl MP119
.ds Hr Introduction to Unix
.PH "~~~~~~~~~~~~~~~Objectives~for~Unit~II" 5 2 2 3
.PP
When you complete this unit, you will be able to:
.sp
.L1 5 2 1
Depict the internal structure of directories.
.L1
Define the word 'Pathname' and 'root' directory.
.L1
Reference another user's directory.
.L1
Create directories
.L1
Delete directories
.L1
Transfer from one directory to another
.L1
Copy files from other user's directories as well as from one of
your directories to another.
.E1
.af % 1
.ds F1 - % -
.ds Fd
.ds F3  ~
.ds Fl  Unit~II
.ds Fr  Module~I
.ds H1  ~
.ds Hl MP119
.ds Hr Introduction to UNIX
.bp
.PH "~~~~~~~~~~~~~~Module I -- Internal Structure"
.PP 5
This module covers Unit II objectives 1, 2, and 3.
.sp
.PH"Objectives"
.PP
After completion of this module the student will be able to:
.sp
.L1 5 2 1
Distinguish between a file and a directory
.L1
Define the word 'Pathname'
.L1
Recognize several system directories
.L1
Define 'root directory'
.L1
Construct pathnames
.L1
Reference other user's files
.L1
Determine the current working directory
.L1
Depict the internal structure of a network of directories
.E1
.bp
.PH "Directories"
.PP
As mentioned in unit I, you are assigned a directory by
the system.  This directory is called the "login directory" and
is being used to hold the files you've been creating.  In addition
to this directory, you may create as many other directories,
referred to as subdirectories, as you need.  You are probably
asking yourself, why do I need other directories.  Well,
subdirectories are used to group together files containing
related information.  For example, suppose you are secretary to several
persons, wouldn't it be easier for you to file each person's
work in a separate drawer, than have everyone's work in
the same drawer.  This feature is used for the same purpose; it merely
facilitates accessing and storing of your files.  Let's look at the
scheme below depicting a network of directories.
.sp
.nf
		    dir  (login directory)

		   /   \\

		 /       \\

	       /           \\

	     dir1            dir2

	   /  |   \\            \\

	 /    |     \\             \\

       /      |        \\             \\

     dir1A  dir1B        dir1C        dir2A

	      |                         |

	      |                         |

	    dir1BA                    dir2B


.fi
.PP
The names appearing in the scheme have no real significance,
They represent the names of directories.  Directory names are
formed in the same manner as file names -- arbitrarily choosen,
not to exceed 14 characters.
.PP
Now, to get back to the diagram; 'dir', the login
directory contains two subdirectories (dir1 and dir2) in
addition to other files.
.PP
If you were to list the table of contents for the
login directory, the information displayed for the directories
would differ only slightly from that of a file.
.sp
.ti 20
eg.  ls -l
.sp
Results similar to this will be displayed:
.sp
.ti 15
drwxr--r-- 5  mmw   632 Feb 28 1205 dir1
.sp
.ti 15
drw-r--r-- 3  mmw 1028 Mar 2 1005 dir2
.sp
.PP
You will notice that a "d" appears in the first position
instead of a '-'; this indicates that this is a directory
instead of a file.  Also, in the 11th position there is a "5" instead
of a "1"; this denotes the number of links or names directly associated
with this particular directory. Let's determine the 5 names associated
with "dir1"-- (1) the login directory name (dir), (2) the directory name
(dir1) and (3) the 3 subdirectories; dir1A, dir1B, and dir1C. when
using the "ls" command to list information pertaining to a file,
this position should be a "1".
.PP
Now suppose you are in directory "dir1" instead of directory "dir"
and you issue the command:
.sp
.ti 25
% ls -l
.sp
Results similar to this will be displayed:
.in 8
.sp
drwxr--r-- 2 mmw    32 Mar  4 09:00 dir1A
.br
drwxr--r-- 3 mmw   824 Mar  1 11:00 dir1B
.br
drwxr--r-- 2 mmw  1026 Feb  2 08:00 dir1C
.in -8
.sp
Main points to remember:
.L1 5 2 1
Directories may contain files and other directories
.L1
Directories are named in the same manner as files
.L1
All users have a login directory
.E1
.ne 10
.sp
.in 6
.ti -6
Note: Your current directory which in this case is your login directory
can be referenced by a period (.); therefore, the above list command
can be formed as  "%ls -l .".  Notice, the period follows the -l option.
It is used to replace the directory name.
.in -6
.PH "Pathnames"
.PP
I know that your next question will probably be, how can
I get from my login directory to one of my subdirectories.
.PP
Well, first try to visualize the network of directories
diagram.  Okay, now relate it to a tree, where the login directory
is the trunk of the tree and the subdirectories are the branches.
Let's go a step further, how would you get to the top of the tree
from the ground? Right, you would begin climbing first to one branch
then to another, in other words, you would follow some path until
you reached your destination.
.PP
You are going to take the same approach here by tracing a
path from the login directory to the desired directory.  This
path is established by forming a list of all the directories
you encounter on the way; separate each by a slash.
.PP
The period (.) shall be used to refer to your login directory
,since we haven't discussed how to explicitly reference it.
.sp
Example:  Your goal is to be in directory "dir1ba" ; thus, the
pathname would be: "./dir1/dir1b/dir1ba"
.PP
Consequently, a pathname represents the full name of the
path you have to follow through the tree of directories to
get to a particular directory or file; also in any command that a
filename or directory name may be specified, a pathname may be
specified.
.sp
.ti 13
Example:~~% ls ./dir1/dir1b/dir1ba
.sp
What do you think will be displayed from the above? Come on, take
a guess.
.sp 2
Right you are, this would list the names of all the
files in "dir1ba".  See how much confidence I have in you.
.sp
.in 6
.ti -6
Note: The filename/filenames may be replaced by the appropriate
pathname/pathnames in all of the commands discussed in
Unit I.
.in -6
.PH "System directories"
.PP
Now for a look at the internal structure of the Unix system
in its entirety.  The system is composed of system directories and
user directories.  In the last section you saw a hypothetical
example of one user's directory which represented only one branch
on our large tree.  The diagram below represents a more complete
picture of the Unix system.
.nf

				 / (this slash, represents the
					      root directory)
			      /  |   \\

			    /    |       \\

	etc     bin    lib       u?        usr    tmp     dev

	/ \\      /\\    /\\   /  |  \\      /\\   /\\      /\\

			    /     |     \\

			 /      robin      \\

		     pam        /   |        angie

			     /      |          |

			 dir1      dir2        |

		      /   |   \\     |        dir3

		  dir1a dir1b dir1c  dir2a
			  |           |

			  |           |

		       dir1ba       dir2b

.fi
.ne 10
.PP
The "Root" directory is the "parent" directory for the entire
system and contains the system directories: etc, bin, u?, usr,
lib,tmp, and dev.  These directories consist of executable files
that maintain the system, such as: keeping a record of all persons
using the system, keeping a record of all valid passwords,
storing and accessing commands when referenced, and other similar
functions.  Don't concern yourself about remembering these
directories; the purpose of mentioning them is to give you a
complete picture of the system.
.PP
However, there is one category of directories on which I want you to
focus your attention, u?.  These directories holds all the valid
login names for the system.  The "?" is a number 1-8; the number
assigned to you and some other users might be "3".  Hence, to reference your
login directory, you begin by specifying: root(/), then the directory
which holds your login name (u3), a slash, and your login name.
.sp
.ti 20
Example:  /u3/mmw
.PP
There are two types of pathnames which may be formed; a full
pathname, and simple pathname.  A full pathname is formed by beginning
with the "root" directory; whereas, a simple pathname is formed by
beginning with the current directory name (the directory you are currently
in).  This will be further discussed in the section on "changing directories".
.PP
Let's refer back to the diagram and assume your login-name
is robin and you want to display a file "junk" from your login
directory; form the command using the full pathname instead of just
the filename.
.sp 2
Is your answer one of the following:
.sp
.in 20
% cat /u3/robin/junk
.br
% pr /u3/robin/junk
.in -20
.PP
Pat yourself on the back if it is, you deserve it; otherwise
please reread this section until you have a clear understanding of
this concept.
.ne 5
.PP
Okay, now form the command to display the file "junk1" from
the directory "dir1b".
.PP
You had to climb a couple of branches in our tree to get to
"dir1b" didn't you? Did you indicate this in forming your
pathname? If you did, you should have:
.sp
.ti 15
% cat /u3/robin/dir1/dir1b/junk
.sp
Give yourself a couple of pats if you got this correct.
.sp
.in 6
.ti -6
Note: Remember to always begin with the login or current directory, list
all subdirectories along the path, and end with the filename when
referring to a particular file.  Got it?
.in -6
.sp
Lets do one more, what would be the results of the following:
.sp
.ti 18
% ls /u3/robin/dir2/dir2a
.sp
Write your answer in the space provided:
.sp 2
You are correct, if your answer is:  A list of all filenames in "dir2a"
will be displayed.  You may proceed to the next section.
.PH "Using your-neighbor's files"
.PP
The ability to use pathnames affords you a tremendous
amount of flexibility.  You are no longer confined to using
only the files created by you -- you can now reference files
created by other users.  All you have to know is the other
users login-name.
.PP
This feature can be extremely beneficial if several persons
are working on the same project.  It can also be used to avoid
the duplicating of efforts -- someone may already have a file
containing the information you need, so why bother to create
an identical file.
.PP
Let's again refer to the previous diagram and assume that you
are 'robin'.  Suppose 'pam' had a file 'letters' containing
information on how to format a business letter and you
wanted a copy of it.  You can get it by using one of the following
commands:
.sp
.in 20
% cat /u3/pam/letters|opr
.br
% opr /u3/pam/letters
.br
% pr /u3/pam/letters
.in -20
.sp
Can you think of another variation? Sure you can -- you could
pipe the results from the last command to the printer.
.PP
Now suppose you want to determine which files are stored in
angie's 'dir3' directory, what would you do?
.sp 3
You're on the ball today -- that's just what you would do.
You would form the command:
.sp
.in 20
% ls /u3/angie/dir3
.br
.ti +8
or
.br
% ls -l /u3/angie/dir3
.in -20
.ne 10
.PH "Print working directory"
.PP
This feature is used to determine which directory
you are currently using, that is, in which directory are you
creating files, or displaying files, etc.  I realize this
probably seems quite vague to you, since you are only using
one directory, your login directory.  However, in the next
module you will learn how to transfer from your login
directory to one of your subdirectories, and from  one
subdirectory to another subdirectory.  Then you will really
appreciate this command.
.PP
But, for now, it will give you a clearer understanding
of pathnames and directories.  The command is:
.sp
.ti 25
% pwd
.sp
.PP
This will cause the system to display the pathname of your
current or working directory.  What should you see displayed when
you issue the above command?
.sp 2
If you said; /u3/your login-name, you are doing fine.
Otherwise, re-read the section on System directories.
.PH "How To Find Out Whose Directories Are Where"
.PP
Suppose you just tried to list the files of the systems guru
whose login name is "dlm", by typing : ls /u3/dlm, and you get a response
that the directory does not exist.  What then?  Well, this simply means
that the person's files aren't located on the "u3" directory.  So, just
where are the person's files?
.PP
Hint: The system maintains a list of all users and where their
login directories can be found.  The pathname used to reference this
list is "/etc/passwd".
.PP
What will "%grep dlm /ect/passwd" give you?
.sp 2
Answer: Why the login directory name for dlm of course.
The "grep" command searches the login directory list
for the login-name dlm.  The directory name is the last
entry on the line displayed by the system, and is
delimited by colons. eg.  :/usr/dlm:
.sp
Remember to use "grep" when you want to determine
someone's login directory.
.PH "Exercises"
.sp
.L1 5 2 1
Issue the "pwd" command.
.L1
Issue the command: % ls /u3/<your login name>.
.L1
Display a file using its pathname instead of just its filename.
.L1
Determine the login directory pathname for "mmw".
.E1
