What a Hierarchical File System Is All About

In a nutshell, a hierarchy is a system organized by graded categorization. A familiar example is the organizational structure of a company, where workers report to supervisors and supervisors report to middle managers. Middle managers, in turn, report to senior managers, and senior managers report to vice-presidents, who report to the president of the company. Graphically, this hierarchy looks as shown in Figure 3.1.

Figure 3.1. A typical organizational hierarchy.


You've doubtless seen this type of illustration before, and you know that a higher position indicates more control. Each position is controlled by the next highest position or row. The president is top dog of the organization, but each subsequent manager is also in control of his or her own small fiefdom.

To understand how a file system can have a similar organization, simply imagine each of the managers in the illustration as a “file folder” and each of the employees as a piece of paper, filed in a particular folder. Open any file cabinet, and you probably see things organized this way: filed papers are placed in labeled folders, and often these folders are filed in groups under specific topics. The drawer might then have a specific label to distinguish it from other drawers in the cabinet, and so on.

That's exactly what a hierarchical file system is all about. You want to have your files located in the most appropriate place in the file system, whether at the very top, in a folder, or in a nested series of folders. With careful usage, a hierarchical file system can contain hundreds or thousands of files and still allow users to find any individual file quickly.

On my computer, the chapters of this book are organized in a hierarchical fashion, as shown in Figure 3.2.

Figure 3.2. File organization for the chapters of Sams Teach Yourself UNIX in 24 Hours, Second Edition.


Task 3.1: The UNIX File System Organization

A key concept enabling the UNIX hierarchical file system to be so effective is that anything that is not a folder is a file. Programs are files in UNIX, device drivers are files, documents and spreadsheets are files, your keyboard is represented as a file, your display is a file, and even your tty line and mouse are files.


What this means is that as UNIX has developed, it has avoided becoming an ungainly mess. UNIX does not have hundreds of cryptic files stuck at the top (this is still a problem in DOS) or tucked away in confusing folders within the System Folder (as with the Macintosh).

The top level of the UNIX file structure (/) is known as the root directory or slash directory, and it always has a certain set of subdirectories, including bin, dev, etc, lib, mnt, tmp, and usr. There can be a lot more, however. The following code shows files found at the top level of the mentor file system (the system I work on). Typically, UNIX directories are shown followed by a slash in the listing.

AA         boot      flags/      rf/         userb/    var/
OLD/       core      gendynix    stand/      userc/
archive/   dev/      lib/        sys/        users/
ats/       diag/     lost+found/ tftpboot/   usere/
backup/    dynix     mnt/        tmp/        users/
bin/       etc/      net/        usera/      usr/

You can obtain a listing of the files and directories in your own top-level directory by using the ls -C -F / command. (You'll learn all about the ls command in the next hour. For now, just be sure that you enter exactly what's shown in the example.)

On a different computer system, here's what I see when I enter that command:

% ls -C -F /
Mail/        export/        public/
News/        home/          reviews/
add_swap/    kadb*          sbin/
apps/        layout         sys@
archives/    lib@           tftpboot/
bin@         lost+found/    tmp/
boot         mnt/           usr/
cdrom/       net/           utilities/
chess/       news/          var/
dev/         nntpserver     vmunix*
etc/         pcfs/

In this example, any filename that ends with a slash (/) is a folder (UNIX calls these directories). Any filename that ends with an asterisk (*) is a program. Anything ending with an at sign (@) is a symbolic link, and everything else is a normal, plain file.

As you can see from these two examples, and as you'll immediately find when you try the command yourself, there is much variation in how different UNIX systems organize the top-level directory. There are some directories and files in common, and once you start examining the contents of specific directories, you'll find that hundreds of programs and files always show up in the same place from UNIX to UNIX.

It's as if you were working as a file clerk at a new law firm. Although this firm might have a specific approach to filing information, the approach may be similar to the filing system of other firms where you have worked in the past. If you know the underlying organization, you can quickly pick up the specifics of a particular organization.

  1. Try the command ls -C -F / on your computer system, and identify, as previously explained, each of the directories in your resultant listing.

The output of the ls command shown previously shows the files and directories in the top level of your system. Next, you learn what the commonly found directories are.


The bin Directory

In UNIX parlance, programs are considered executables because users can execute them. (In this case, execute is a synonym for run, not an indication that you get to wander about murdering innocent applications!) When the program has been compiled (usually from a C listing), it is translated into what's called a binary format. Add the two together, and you have a common UNIX description for an application—an executable binary.

It's no surprise that the original UNIX developers decided to have a directory labeled binaries to store all the executable programs on the system. Remember the primitive teletypewriter discussed in the preceding hour? Having a slow system to talk with the computer had many ramifications you might not expect. The single most obvious one was that everything became quite concise. There were no lengthy words like binaries or listfiles, but rather succinct abbreviations: bin and ls are, respectively, the UNIX equivalents.

The bin directory is where all the executable binaries were kept in early UNIX. Over time, as more and more executables were added to UNIX, having all the executables in one place proved unmanageable, and the bin directory split into multiple parts (/bin, /sbin, /usr/bin).

The dev Directory

Among the most important portions of any computer are its device drivers. Without them, you wouldn't have any information on your screen (the information arrives courtesy of the display device driver). You wouldn't be able to enter information (the information is read and given to the system by the keyboard device driver), and you wouldn't be able to use your floppy disk drive (managed by the floppy device driver).

Remember, everything in UNIX is a file. Every component of the system, from the keyboard driver to the hard disk, is a file.

Earlier, you learned how almost anything in UNIX is considered a file in the file system, and the dev directory is an example. All device drivers—often numbering into the hundreds—are stored as separate files in the standard UNIX dev (devices) directory. Pronounce this directory name “dev,” not “dee-ee-vee.”

The etc Directory

UNIX administration can be quite complex, involving management of user accounts, the file system, security, device drivers, hardware configurations, and more. To help, UNIX designates the etc directory as the storage place for all administrative files and information.

Pronounce the directory name either “ee-tea-sea”, “et-sea,” or “etcetera.” All three pronunciations are common.

The lib Directory

Like your neighborhood community, UNIX has a central storage place for function and procedural libraries. These specific executables are included with specific programs, allowing programs to offer features and capabilities otherwise unavailable. The idea is that if programs want to include certain features, they can reference just the shared copy of that utility in the UNIX library rather than having a new, unique copy.

Many of the more recent UNIX systems also support what's called dynamic linking, where the library of functions is included on-the-fly as you start the program. The wrinkle is that instead of the library reference being resolved when the program is created, it's resolved only when you actually run the program itself.

Pronounce the directory name “libe” or “lib” (to rhyme with the word bib).

The lost+found Directory

With multiple users running many different programs simultaneously, it's been a challenge over the years to develop a file system that can remain synchronized with the activity of the computer. Various parts of the UNIX kernel—the brains of the system—help with this problem. When files are recovered after any sort of problem or failure, they are placed here, in the lost+found directory, if the kernel cannot ascertain the proper location in the file system. This directory should be empty almost all the time.

This directory is commonly pronounced “lost and found” rather than “lost plus found.”

The mnt and sys Directories

The mnt (pronounced “em-en-tea”) and sys (pronounced “sis”) directories also are safely ignored by UNIX users. The mnt directory is intended to be a common place to mount external media—hard disks, removable cartridge drives, and so on—in UNIX. On many systems, though not all, sys contains files indicating the system configuration.

The tmp Directory

A directory that you can't ignore, the tmp directory—say “temp”—is used by many of the programs in UNIX as a temporary file-storage space. If you're editing a file, for example, the program makes a copy of the file and saves it in tmp, and you work directly with that, saving the new file back to your original file only when you've completed your work.

On most systems, tmp ends up littered with various files and executables left by programs that don't remove their own temporary files. On one system I use, it's not uncommon to find here 10–30 megabytes of files wasting space.

Even so, if you're manipulating files or working with copies of files, tmp is the best place to keep the temporary copies of files. Indeed, on some UNIX workstations, tmp actually can be the fastest device on the computer, allowing for dramatic performance improvements over working with files directly in your home directory.

The usr Directory

Finally, the last of the standard directories at the top level of the UNIX file system hierarchy is the usr—pronounced “user”—directory. Originally, this directory was intended to be the central storage place for all user-related commands. Today, however, many companies have their own interpretation, and there's no telling what you'll find in this directory.

Standard practice is that /usr contains UNIX operating-system binaries.


Other Miscellaneous Stuff at the Top Level

Besides all the directories previously listed, various other directories and files commonly occur in UNIX systems. Some files might have slight variations in name on your computer, so when you compare your listing to the following files and directories, be alert for possible alternative spellings.

A file you must have in order to bring up UNIX at all is one usually called unix or vmunix, or named after the specific version of UNIX on the computer. The file contains the actual UNIX operating system. The file must have a specific name and must be found at the top level of the file system. Hand-in-hand with the operating system is another file called boot, which helps during initial startup of the hardware.

Notice on one of the previous listings that the files boot and dynix appear. (DYNIX is the name of the particular variant of UNIX used on Sequent computers.) By comparison, the listing from the Sun Microsystems workstation shows boot and vmunix as the two files.

Another directory you might find in your own top-level listing is diag—pronounced “dye-ag”—which acts as a storehouse for diagnostic and maintenance programs. If you have any programs within this directory, it's best not to try them out without proper training!

The home directory, also sometimes called users, is a central place for organizing all files unique to a specific user. Listing this directory is usually an easy way to find out what accounts are on the system, too, because by convention each individual account directory is named after the user's account name. On one system I use, my account is taylor, and my individual account directory is also called taylor. Home directories are always created by the system administrator.

The net directory, if set up correctly, is a handy shortcut for accessing other computers on your network.

The tftpboot directory is a relatively new feature of UNIX. The letters stand for “trivial file transfer protocol boot.” Don't let the name confuse you, though; this directory contains versions of the kernel suitable for X Window System–based terminals and diskless workstations to run UNIX.

Some UNIX systems have directories named for specific types of peripherals that can be attached. On the Sun workstation, you can see examples with the directories cdrom and pcfs. The former is for a CD-ROM drive and the latter for DOS-format floppy disks.

There are many more directories in UNIX, but this will give you an idea of how things are organized.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset