3.1 Files and Directories

How files and directories are organized

In Unix, as with DOS or Macintosh, each file must have a name, and that name must appear in a directory somewhere. A directory is a special kind of file that acts as a "container" for other files, thus gathering them in a convenient place. Since each directory is a file too, it has a name and must appear in some other directory, called its parent directory. The single exception to this is the root directory, named '/', which is its own parent.

It is helpful to think of directories and files as sitting in a tree-like structure, like this:

This picture shows us a directory, called /home/ugrad/myname, which contains four files. Three of the files are plain files (i.e. not directories), and the file Dir2 is another directory, contained inside its parent directory.

Of course, Dir2 is a directory in its own right, and contains two plain files. It could as easily have contained yet another directory, since there is no practical limit to the number of directories you can nest, one inside the other.

Notice the slashes in the directory name. The series of directory names and slashes, called a pathname, tells Unix how to descend the directory tree to find your file. For example, to tell Unix about the file Project.m, we could use the pathname /home/ugrad/myname/Dir2/Project.m


Keith Orpen, who is still writing this, would like to hear your comments and suggestions.