Directories



next up previous contents index
Next: Your Home Directory Up: Setting Up Files Previous: Setting Up Files

Directories

A system with many users will have hundreds or thousands of files, some useful, a few valuable. To organize and protect these files, Unix lets you group them into directories. Directories are like hanging file folders in a filing cabinet with each directory containing a number of files, as well as other directories (subdirectories). Accordingly, when you open (or change to) a directory, you gain access to all files and subdirectories     contained in that directory.     

As discussed further in The Project Directory Approach, we have found it to be a good idea to use directories as separate work spaces for the many interesting projects and necessary administrative tasks facing hard-working scientists, engineers, and students. You may then edit, compile, and run programs within one directory without affecting files in other directories (although you can still access other directories). 

 

 
Figure 1.1: Unix file system tree.

The ability of Unix to have directories within directories makes it hierarchical. As an example, in Figure1.1 is a schematic of a typical Unix file system. Note that all files or directories are below (or in) the topmost or root directory denoted by the `` / '' symbol. The usr and local directories are expanded, showing how (sub-) directories are further organized within directories. Notice, too, that while the names bin, etc, and lib are used more than once, each is unique since each resides within a different parent directory (each has a unique full name). Since root (/) is the root of all directories, the full path name begins there. For example, the three lib's have the full path names      
/lib /usr/lib /usr/local/lib
Here the name begins at the root directory /, and after that shows the path through all the directories to get to each lib. This notation is somewhat confusing at first, since each directory name is also separated by a /, but these later /'s are just separators; don't blame us, we're just the bearers of bad news who also must bear bad notation.

The Unix file system tree can be quite confusing even to experienced users, probably because the human mind believes there must really be some logic in such a complicated construct. At one time there may have been a clear rationale for which files were placed in various directories and subdirectories, the proliferation of new commands, the addition of commercial software, and the fusion of System V and BSD Unix have left the branches in the tree rather tangled with few general rules.

The term usr is an abbreviation for user service routines, while the directory /u is where the users' home directories are kept. The directories bin, etc, and lib under / contain the basic programs and files needed for the system to boot and run, while the directories under usr contain programs and files that are for the users. Often this same arrangement is duplicated under /usr/local where programs are installed by the local system administrator. In the bin (binary) directory are stored executable programs, while the lib (library) directory contains object files used by other programs as well as the libraries used by compilers to create executable programs. The etc directory is basically everything else, and, in particular, the system and user configuration files as well as the password file passwd.           

If you want to know who your real friends are, or at least fellow users, you can look at the users' directories in /u or /users. The home directories of your fellow users and their login names will be there. In fact, unless a user makes an extra effort to be private, you can probably go snooping through their file system. Be careful: it is unethical and sometimes illegal to read, copy, or modify someone else's files or to use a system on which you are not an authorized user.

Fortunately, a user seldom needs to know the location of the file containing a particular command since the shell will automatically search through a list of directories to find the file containing the command entered. The actual list is kept in a shell variable, or environment variable, called PATH (which is identical to the PATH variable used in MS-DOS). The PATH is defined differently for different shells, so you may need to consult the examples given in A Word about Your PATH. Or, better yet, develop a positive attitude and go exploring and experimenting.      

If you must find the location of a command, there are some tools to help you. The command whereis will try to locate a command, while the command which will show you which of several possibly different programs with the same name will be executed. These commands are shell and system dependent and may not be on all systems. There also is the standard Unix utility find which will recursively search the file system tree for a file; however, its thoroughness may make it appear incredibly slow on some machines.



next up previous contents index
Next: Your Home Directory Up: Setting Up Files Previous: Setting Up Files