The Unix File SystemNavigating the hierarchical directory structure |
|
From "Migration", Access to Wang, October 1993 |
|
[ Prior Article ] [ Return to the Catalog of articles ] [ Next Article ] |
For all their apparent complexity, Unix systems have a relatively straightforward hierarchy of directories that guides the experienced user to the locations of critical files. An experienced Unix user can approach a new system and find these elements quickly, even though each installation may have radically different hardware arrangements and non-standard names for other directories. The key is understanding the logic behind this hierarchy.
To perform administrative work from the command prompt, it is necessary to move comfortably around within the directories in the file system. Let's take a look at how to do this.
When you log onto a Unix system, you are normally positioned in your home directory. The location of this directory varies with the personal conventions of Unix users, but it is often located at /usr/uid (where uid is your initials) or /home/uid. To test the location on your system, enter pwd (print working directory) immediately after logging onto the system and note the result.
Moving to another directory is accomplished by typing the cd (change directory) command followed by the directory location you wish to go to. To change to the /bin directory, enter cd /bin. Check your location afterwards with the pwd command or by listing the files in the directory using ls. This is an example of an absolute directory movement; you have indicated the directory location explicitly, starting from the root location (/) of the file system.
Directory movements can also be made relative to your current position. Examine the sample directory listing in Figure 1 and you will see several directories (Mail, scripts, temp, and work). If the current working directory location is /usr/dsb, you could change to the temp directory by entering cd temp. This command functions the same as cd /usr/dsb/temp but is easier to type.
A special form of relative directory commands allows movement down the directory tree without specifying a directory name. The sample directory listing below also shows a file name consisting of two periods; this is not a file but actually a route back to the directory a level above. If your current working directory location is /usr/dsb/temp, enter cd .. (two periods) to move back to /usr/dsb.
Tricky relative movements are also possible by combining upward and downward movements into a single command. If your current directory location is /usr/dsb/temp, as before, you can move to /usr/dsb/work by entering cd ../work. This translates to "move one directory up, then change to the work directory."
A caution to those familiar with MS-DOS directory commands: the cd command without any arguments behaves differently than you might expect. In MS-DOS, entering cd alone shows the current directory location - similar to executing the pwd command in Unix. On Unix systems, entering the cd command alone will return you to your home directory. In most other respects, directory movement is similar.
Also, it is not always possible to change to a directory or list its contents. Unix security allows directories to be protected such that casual directory listings are not possible - even though the files in the system are accessible in other ways, such as read-only access to data files or execution access to programs. This is somewhat like hidden files or directories in MS-DOS, but the protection can be controlled through membership in groups, Access Control Lists, and other means.
The hierarchy of a typical file system is displayed graphically in Figure 2. In this example, the home directories of users are located within /usr; note that there are other directories present that are not home directories, such as /usr/local/bin and /usr/lost+found. Since every user has their own home directory, it is customary on large systems to place these within another directory area such as /home or /users so they are not mixed with other system-related subdirectories.
Like any operating system, Unix uses parameters stored in files to control device configuration, user names, and other important information. Most of these files are text files, but somewhat different than the fixed-field consecutive files found on the VS. Unix systems use variable-length fields separated by commas, colons, or some other character.
Unix systems have similar directory locations for system configuration files, grouped by their function. Some of these directories include:
/bin: Short for binary, or machine-level program code. Holds executable files essential for system operation.
/dev: Contains device files, the means to getting data in and out of terminals, modems, and other devices.
/etc: System administration tools and files, including the password file.
/lost+found: Holds files that have been lost due to a system problem or other extraordinary event.
/tmp, /usr/tmp: Directories for temporary work files. Must be cleared periodically of old files.
/usr/bin: Executable files not part of the core operating system. Most user programs reside here.
/usr/lib: Contains Unix libraries, which are archives of program functions. Also contains help files, system accounting, fonts, and the crontab file, which controls the cron background scheduler.
/usr/local/bin: Executable files specific to this installation.
/mnt: A mount point for other file systems, merging their directories and files into that of the root file system.
/usr/src: Source files for the operating system. Often misused as storage for site-specific program source.
/usr/spool: Files and subdirectories that are created routinely as a part of other processes and must be emptied periodically.
Try using the cd command to move to these directories and the ls command to list their contents. Since there may be a large number of files in some of these directories, it may be best to pipe the directory listings into the more filter to keep the listing within the screen. (Example: ls -la | more.)
Now that the directory locations of the important files have been identified, let's look closer at some of the files within these directories.
All multi-user operating systems have a means of establishing the identity of users and checking whether they should have access to the resources of the system. The system administrator must set up these user names and the level of access they are allowed. In the VS world, such administration in carried out in the SECURITY utility, with most effects to the USERLIST file, located in the system library.
Unix systems require similar attention, along with additional choices for security level, type of user environment, and other items. In spite of these similarities, "pure" Unix systems do not contain high-level utilities like SECURITY for system administration. Most vendors of Unix systems, add such tools to make administration simpler, but a large number of Unix sites use text editors and home-grown programs for these important tasks. The lesson: be sure to check out the system administration tools before considering any Unix vendor seriously.
The /etc/passwd file contains all of the information necessary to identify valid users and set up their environment. It contains seven fields, each separated by a colon: the user ID (initials), a password, a unique user ID number (uid), group ID (gid), full name, home directory, and startup program. The user password appears as seemingly random text; the user's password is encrypted within. Setting the uid field to a unique number is usually the task of vendor-supplied system administration tools. The startup program field typically contains the user's choice for a shell, or command environment; the Bourne shell is the likeliest default if this field is left blank.
The /etc/group file ties user IDs to group membership, which is used for security purposes throughout the system. Files and directory access and program execution can be controlled through membership in groups. Like /etc/passwd, the /etc/group file consists of variable-length fields separated by colons. /etc/group has four fields: a group name, a group password (typically set to VOID, or no password), a unique group number, and the user initials for all members of the group, separated by commas.
One of the most important contents of each user's home directory is their .profile file. This file is used during startup to set up the user's command environment, invoke special commands, and provide fine-tuning to the workstation definition. A text file, the profile can contain any commands that need to executed every time the user logs on. .profile is a hidden file, not shown on most directory listings due to the period beginning its name.
Other common home directory contents .exrc and the Mail subdirectory. The .exrc file contains user preferences for the vi text editor, commonly used to create and edit mail messages as well as for source file editing. If your organization uses the internal Unix mail system the Mail subdirectory will be present in each user's home directory.
Other than system files, Unix allows nearly any other directory structure for site-specific files. If you have access to one or more Unix systems, check to see how their file systems are arranged. Also look to see if the system administration files are located in the areas mentioned here.
I look forward to your question and comments.
UNIX System V Release 4 Administration, Second Edition
David Fielder and Bruce H. Hunter
Hayden Books, Carmel, Indiana; 1991
Lays out system administration tasks and concepts for systems based on the latest release of AT&T UNIX. Includes many helpful scripts for administrative chores. Combines a reference and tutorial format.
Figure 1: Sample Unix Directory Listing
total 208 drwx------ 15 dsb dp 2048 Jul 11 10:21 . drwxr-xrwx 163 sys sys 6144 Jul 8 10:59 .. -rwxr--r-- 1 dsb dp 748 May 4 05:48 .alias -rw-r--r-- 1 dsb users 360 Oct 21 1992 .exrc -rw-r--r-- 1 dsb dp 0 May 13 1992 .news_time -rw-rw-r-- 1 dsb dp 922 Jul 11 10:48 .profile -rwxr--r-- 1 dsb dp 12 Jun 4 07:18 a.FILE.name drwx------ 2 dsb mail 64 May 21 1992 Mail drwxrwxrwx 2 dsb dp 1024 Jun 7 23:01 scripts drwxrwxr-x 2 dsb users 44032 Jul 9 18:34 temp -rwxrw-r-- 1 dsb users 748 Jun 4 07:18 userfile drwxrwxr-x 2 dsb users 1024 Jul 9 14:34 work
Figure 2: Sample Unix File System Hierarchy
/ (root) |---bin |---dev |---etc |---lost+found |---tmp
--usr |---abc |---Mail
--dsb |---Mail |---scripts |---temp
--work |---lib |---local
--bin |---lost+found |---src |---spool
--xyz |---Mail \---scripts
Copyright © 1993 Dennis S. Barnes
Reprints of this article are permitted without notification
if the source of the information is clearly identified