The Hierarchical File Structure


Because directories can contain other directories, which can in turn contain other directories, the UNIX file system is called a hierarchical file system. Within the UNIX System, there is no limit to the number of files and directories you can create in a directory that you own. File systems of this type are often called tree-structured file systems, because each directory allows you to branch off into other directories and files. Tree-structured file systems are usually depicted upside-down, with the root of the tree at the top of the drawing. Figure 3–1 depicts a typical hierarchical tree structure.

image from book
Figure 3–1: A sample directory structure

On every UNIX system, the root is a directory called /. In Figure 3–1, root contains a subdirectory called home. Inside home you have three subdirectories, each for a different user on the system. One of these subdirectories is for the user whose login name is raf; in that directory are two subdirectories (Email, Work) and a file (notes.august); and in those directories are other subdirectories or files (inbox, save, sent,final, save).

The directory in which you are placed when you log in is called your home directory. Generally, every user on a UNIX system has a unique home directory, often with the same name as their login name. In every login session, you start in your home directory and move up and down the directory tree. (Sometimes users have several home directories, each used for specific purposes, but beginning users do not need to worry about this.) There is a maximum number of directories a user can have; this number is set by the system administrator to prevent a user from ruining a file system.

Pathnames

Notice in Figure 3–1 that there are two files with the same name, but in different locations in the file system. There is a save file in the Email directory, and another file called save in the Work directory. In order to distinguish files with the same name, the UNIX System allows you to specify filenames by including the location of the file in the directory tree. This type of name is called a pathname, because it is a listing of the directories you travel through along the path you take to get to the file. The path through the file system starts at root (/), and the names of directories and files in a pathname are separated by slashes.

For example, the pathname for one of the save files is

 /home/raf/Email/save

and the pathname for the other is

 /home/raf/Work/save

Pathnames that trace the path from root to a file are called full (or absolute) pathnames. Specifying a full pathname provides a complete and unambiguous name for a file. In a full pathname, the first slash (/) refers to the root of the file system. All the other slashes separate the names of directories, until the last slash separates the filename from the name of the directory it’s in.

Using full pathnames can be awkward when there are many levels of directories, as in this filename:

 /home/dkraut/Work/cs106x/Proj_1/lib/Source/strings.c

In cases like this, using the full pathname requires a good memory and a lot of typing. In Chapter 4 you will learn how to use shell variables as a shortcut to specify pathnames.

Relative Pathnames

You do not always have to specify the full pathnames when you refer to files. As a convenient shorthand, you can also specify a path to a file relative to your present directory Such a pathname is called a relative pathname. Instead of starting with a / for root, the relative pathname starts with the name of a subdirectory For example, suppose you are in your home directory, /home/raf. The relative path for the save file in the Email subdirectory is Email/save, and the relative path for the other save file is Work/save.

Specifying the Current Directory

A single dot (.) is used as a shortcut to refer to the directory you are currently in. This directory is known as the current directory.

Specifying the Parent Directory

Two dots (.., pronounced “dot-dot”) refer to the parent directory of the one you are currently in. The parent directory is the one at the next higher level in the directory tree. Because the file system is hierarchical, all directories have a parent directory The dot-dot references can be used many times to refer to things far up in the file system. The following sequence, for example,

 ../..

refers to the parent of the parent of the current directory. If you are in Work, then ../.. is the same thing as the home directory, since home is the parent of raf, which is the parent of Work.

Specifying a Home Directory

A tilde (~) can be used to refer to your home directory (Strictly speaking, this is a feature of the shell, which will be discussed in the next chapter. It will work on most modern UNIX systems.)

These shortcuts can be combined. For example, if your home directory is /home/raf, then

 ~/../liz

refers to the home directory for the user liz.

You can also use a tilde followed by a login name to refer to another user’s home directory For example, the shortcut ~nate refers to the user nate’s home directory

UNIX and Windows File Structure

The Windows file system was patterned after the UNIX hierarchical file system structure, but with some important differences. On a UNIX System, the root of the file system is depicted as / (slash). The root is the base of the entire system file structure, including files that may be on a different physical disk. In Windows, each drive or partition has a different root. On the main hard drive, the root is usually called C:\. A CD-ROM drive would have a different root than the hard drive (it might be D:\, for example). In addition, Windows uses a \ (backslash) instead of the / (forward slash) that separates directories in UNIX.

For example, this UNIX pathname

 /home/raf

would look like this in Windows:

 C:\home\raf

Note that the forward slashes in the UNIX pathname have become backslashes in the Windows pathname.

You may have noticed that a UNIX pathname looks a lot like part of a web address. That’s because the web inherited this style of pathname from the UNIX file system. The shortcuts for pathnames just described, such as .. for the parent directory, can be used in HTML code for web pages.




UNIX. The Complete Reference
UNIX: The Complete Reference, Second Edition (Complete Reference Series)
ISBN: 0072263369
EAN: 2147483647
Year: 2006
Pages: 316

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net