home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 1.18 Who Handles Wildcards? Chapter 1
Introduction
Next: 1.20 Your Home Directory
 

1.19 The Tree Structure of the Filesystem

A multiuser system needs a way to let different users have different files with the same name. It also needs a way to keep files in logical groups. With thousands of system files and hundreds of files per user, it would be disastrous to have all of the files in one big heap. Even single-user operating systems have found it necessary to go beyond "flat" filesystem structures.

Almost every operating system solved this problem by implementing a tree-structured, or hierarchical , filesystem. UNIX is no exception. A hierarchical filesystem is not much different from a set of filing cabinets at the office. Your set of cabinets consists of many individual cabinets. Each individual cabinet has several drawers; each drawer may have several partitions in it; each partition may have several hanging (Pendaflex) folders; and each hanging folder may have several files. You can specify an individual file by naming the filing cabinet, the drawer, the partition, the group of folders, and the individual folder. For example, you might say to someone: "Get me the `meeting of July 9' file from the Kaiser folder in the Medical Insurance Plans partition in the Benefits drawer of the Personnel file cabinet." This is backwards from the way you'd specify a filename, because it starts with the most specific part, but the idea is essentially the same.

You could give a complete path like this to any file in any of your cabinets, as shown in Figure 1.2 . The concept of a "path" lets you distinguish your July 9 meeting with Kaiser from your July 9 interview with a job applicant or your July 9 policy planning meeting. It also lets you keep related topics together: it's easy to browse through the "Medical Insurance" section of one drawer or to scan all your literature and notes about the Kaiser plan. The UNIX filesystem works in exactly the same way (as do most other hierarchical filesystems). Rather than having a heap of assorted files, files are organized into directories . A directory is really nothing more than a special kind of file that lists a bunch of other files (see article 18.2 ). A directory can contain any number of files (although for performance reasons, it's a good idea to keep the number of files in one directory relatively small - under 100, when you can). A directory can also contain other directories. Because a directory is nothing more than a special kind of file, directories also have names. At the top (the filesystem "tree" is really upside down) is a directory called the "root," which has the special name / (pronounced "slash," but never spelled out).

Figure 1.2: A Hierarchical Filesystem

Figure 1.2

To locate any file, we can give a sequence of names, starting from the filesystem's root, that shows its exact position in the filesystem: we start with the root and then list the directories you go through to find the file, separating them by slashes. This is called a path . For examples, let's look at the simple filesystem represented by Figure 1.3 . The names /home/mkl/mystuff/stuff and /home/hun/publick/stuff both refer to files named stuff . However, these files are in different directories, so they are different files. The names home , hun , and so on are all names of directories. Complete paths like these are called "absolute paths." There are shorter ways to refer to a file called relative paths ( 1.21 ) .

Figure 1.3: A UNIX Filesystem Tree

Figure 1.3

- ML


Previous: 1.18 Who Handles Wildcards? UNIX Power Tools Next: 1.20 Your Home Directory
1.18 Who Handles Wildcards? Book Index 1.20 Your Home Directory

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System