next up previous contents
Next: Basic UNIX and DOS Up: File Basics Previous: Basic Operations   Contents

Directories

Most of the files you will deal with will be on disk and each file name has to be unique so that the computer knows which one is being referred to. This immediately leads to a problem: what if two users share the same disk and want to use the same file name? The solution is to store files in named DIRECTORIES and to give each user their own directory. Now the complete file name includes the directory name so that each user can have whatever files they like; the name need only be unique within the directory.

This method of dividing up files is so useful that users are allowed to create their own directories. The directories are in fact special files and as they are files, are themselves stored within directories. An example may clarify this. Suppose a user has the directory smith as his main directory. The user works on two experiments: PDK and SNO and wants to keep the files separate for the two experiments. So, in the smith directory two new directories are created: pdk and sno. Now suppose the user wants, for the sno directory to separate files into new, current and old, to do this new, current and old directories are created in the sno directory. All these directories together form a directory TREE which now looks like that shown in figure 4.1.

Figure 4.1: Directory Structure
\begin{figure}\centering
\unitlength=0.1cm
\begin{picture}(130,70)
\put( 43.,60....
...10.){old}
\put( 80.,10.){current}
\put(115.,10.){new}
\end{picture}
\end{figure}

To completely specify a file name, requires also giving the name of the directory that holds it. If the directory is not the main one then the directory that holds it must also be given and so on until the main directory is reached. So, for example, in UNIX, a file in the current directory of sno would have a full file name specification of e.g.:-

/home/smith/sno/current/myfile
The set of directory names form a path starting at the top of the tree and passing down to the required directory. Specifying names like this can become a little tedious so the system provides two short cuts. At all times you have a default (or working) directory and if you give a file name without any directory component, the default directory is assumed. When you first log in the default directory is your main (top level) directory, but the system allows you to change the default at any time. The second short cut is to use RELATIVE DIRECTORY ADDRESSING. In the example above the directory path was shown in full, this is called ABSOLUTE DIRECTORY ADDRESSING. With relative addressing you describe how to get to the directory you want, moving up and down the directory tree, from the default directory. Suppose the default directory is:-
/smith/sno
then
current/
means move down to the CURRENT directory, while:-
../pdk/
means move up to smith and then down to pdk. Any directory can be reached from any other directory in this way, so the choice between absolute and relative addressing is just a matter of convenience.

One word of warning: directory trees can be as complicated as you like, but going too far in this direction might leave you with one file in each directory which makes it even harder to find the file you want than having them all in one directory!


next up previous contents
Next: Basic UNIX and DOS Up: File Basics Previous: Basic Operations   Contents
P.D. Gronbech (IT Staff) 2015-10-02