Think hierarchically

7.10 Think hierarchically

Several years ago it became necessary for the first time to explain to my daughter how to organize files in a directory hierarchy. Before then, she had only a rudimentary knowledge of file system layouts. She understood that there was a directory on the family computer's hard disk with her name on it. If she clicked the mouse pointer on the correct icons in the GUI, she could obtain a list of those files she considered her own.

Alas, youth has more time than experience. As a nine-year-old, she had enough free time to create a collection of drawings so large that the file listings would scroll off the screen. In the interest of making her directory more manageable for her, I showed her the benefits of creating multiple subdirectories for her picture files. It didn't take long before she realized that she could also create directories within directories, so she could organize her drawings in neatly organized electronic folders nestled five levels deep.

She had learned to think hierarchically.

It's a simple idea, but like so much else in Unix, it has profound significance. While it seems obvious to many today that file systems should be laid out hierarchically, this wasn't always so. Early operating systems often placed system-related files in one directory and the users' files in directories all at the same level in the directory tree. People couldn't see the benefits of hierarchical thinking in those days.

Most modern operating systems organize files and directories in hierarchies, and Unix is no exception. Unix differs slightly from other systems, however, in the syntax one uses to reference files nested deeply within multiple directory levels. Unix is conveniently consistent in using the "/" character to separate the components of a file's path name. Thus:

 /usr/a/users/gancarz/.profile 

represents the file ".profile" in the directory "gancarz." The directory "gancarz" is found within the directory "users," and so on up to the directory "/", which is the "root" directory. [2] The Unix file system hierarchy is essentially an upside-down tree, with the root directory sitting atop successive branches (directories) and leaf nodes (files).

Unix organizes other components hierarchically, too. For example, tasks in Unix, known as processes, occupy a tree structure. Process number 1, the init process, serves as the root of the tree. All other processes—including user sessions—are the offspring of init or its child processes. A process spawns a child process by creating a copy of itself and marking itself as the parent process of the child. Just as in real life, the child process inherits the attributes of its parent.

Another example of the hierarchical approach in Unix is the X Window System's user interface library. It uses a resource manager that allows user interface objects, such as buttons and menus, to inherit attributes from other user interface objects hierarchically. This powerful idea makes it possible for users to customize fonts, colors, and other attributes in several components of an application.

Apart from the practical uses within Unix, there is also a philosophical reason for hierarchical thinking. No one can deny that most of nature is ordered hierarchically as well. To use an old cliché, the mighty oak that grows from a small acorn eventually will produce acorns of its own. Those acorns will in turn produce more oak trees. This cycle has been repeating itself since the dawn of time. Similarly, in human nature, parents beget children that in turn grow up to beget children of their own. The idea of a family tree has its roots, so to speak, in the trees of the forest. Since the hierarchical organization of Unix mirrors nature, it's a very good sign that it's probably a good approach.

In this chapter we have explored 10 lesser tenets of the Unix philosophy. It is not expected that all members of the Unix or Linux communities at large will agree with everything discussed here. That is of little concern. The Unix community, like the rest of the free world, allows for a great degree of individual expression and occasional disagreement.

Some of these ideas can also be found in other operating systems. Whether Unix is the originator or the recipient of these tenets is unclear. Nevertheless, many Unix users and programmers follow them, knowingly or otherwise. The same holds true for the Linux community.

[2]Microsoft Windows organizes files and folders hierarchically as well. However, users must always be aware of the physical drive or partition (e.g., the C: drive). The root directory on Unix, however, represents the top of a tree that includes all drives on the system as opposed to having separate root directories for each physical drive. Unix users need not be concerned about the (often complex) physical drive and partition layouts on their systems. Under Unix, it's all one big tree.



Linux and the Unix Philosophy
Linux and the Unix Philosophy
ISBN: 1555582737
EAN: 2147483647
Year: 2005
Pages: 92
Authors: Mike Gancarz

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