Friday, May 27, 2011

Chapter 8. UNIX File System Hierarchy

Chapter Syllabus

8.1 Static and Dynamic Files

8.2 The Root Directory (/)

8.3 The Devices Directory (/dev)

8.4 The /etc Directory

8.5 The Home Directory (/home)

8.6 The System Binary Directory (/sbin)

8.7 The /stand Directory

8.8 The /net Directory

8.9 The Applications Directory (/opt)

8.10 The Temporary File Directory (/tmp)

8.11 The /usr Directory

8.12 The Variable Files Directory (/var)

8.13 The lost+found Directory

8.14 Some Useful Commands Related to File System Hierarchy

UNIX files and directories are arranged in a systematic way, like a tree structure. The root directory is represented by the slash symbol (/). It serves as the root of this directory tree. By file system layout, we mean the arrangement of files and directories in a directory tree. It does not mean the actual physical format of the

disk drive but shows only logical arrangement. Directories in UNIX are named and arranged in a fashion that have particular meaning for users. Every directory contains a particular set of files related to some defined purpose or task. For example, all files in the /etc directory are related to some sort of system configuration task. Similarly, the home directories of all users are usually kept in the /home directory.

There are two major types of file system hierarchies used in UNIX distributions. One of these is based on Berkley Distribution of UNIX (BSD) and the other is AT&T System V. The file system layout of HP-UX version 10.x and above is based on AT&T system V release 4 (SVR4). The directory structure starts with the root directory. All other directories are named relative to the root directory. There are two major groups of these directories. One is the group in which system files are present and don't change frequently. This is the static part of the directory hierarchy. The other group contains those files and directories that are changed on a routine basis and are sometimes called dynamic files and directories. An example of this type of file is log files that change on a day-to-day basis. Another division of directories may also be based on shared and nonshared files.

This chapter contains an introduction to the directory tree and the types of files in each directory. We will describe what directories are related to system files and what are used by HP-UX users. Through a careful study of the chapter, a user will build understanding of how to quickly find different files and directories used for particular purposes. As examples, you will learn where files containing manual pages are located and what directory contains files related to network administration.

8.1 Static and Dynamic Files

Static files and directories contain information that usually does not change after system installation. The files that fall into this category are executable files, libraries, applications, and so on. This part contains /sbin, /usr, and the

application directories under /opt. As these files are also shared among many systems in a network where diskless or dataless clients are used, they are also called shared files. The dynamic files are those that are found in other directories like the /var directory, which holds most of the log files. In fact, the name var also comes from "variable." Similarly, you place temporary files in the /tmp directory. Most of the applications also put their temporary files in the /var/tmp directory and it continuously changes. Contents of the home directory also change whenever a user is created or deleted or whenever a user makes changes to any of his or her files. Figure 8-1 shows the division of a file system into static and variable directories.

Figure 8-1. Static and dynamic directories.

To keep the logical division of files and directories, HP-UX keeps all application directories separate from system directories so that these two types of files never get mixed with each other. Similarly, executable and nonexecutable files and directories are also kept separate from each other. In the following part of this

chapter, you will get a brief introduction to the contents of each directory under the root directory. The directory tree is specific to HP-UX version 10.x and above.

8.2 The Root Directory ( / )

All of the file system is viewed with reference to the root directory. The name root comes from the logical position of this directory. This is the top-level directory in the tree structure and hence the name root is used for it. It is represented by a slash character (/). It must be kept in mind that the root directory or any other directory is not related to physical disks in any respect. The directory structure is just a logical arrangement regardless of the number of disks in your system or how these disks are partitioned.

8.3 The Device Directory (/dev)

The device directory contains all of the device files. Device files are used to represent devices attached to the system. Each device file has a major and a minor number. The major number of a device file represents a device driver built into the HP-UX kernel, while the minor number represents the device's hardware address and (optionally) certain device-specific options. An instance means a logical numbering of the same type of devices. For example, there may be more than one SCSI disk in a system. All of these SCSI disks use the same device drivers but represent different instances of disks and have different minor numbers.

We will be discussing more about device files in Chapter 17. At the moment, however, it is useful to mention that the device directory contains many subdirectories depending on the types of devices. This is used to group device files in a more logical way. Files related to one type of device are kept in one subdirectory under /dev. Figure 8-2 shows some of these subdirectories.

Figure 8-2. The device directory (/dev) hierarchy.

As an example, the directory /dev/rdsk contains all of the device files that represent character-based or raw devices related to physical disks. The directory /dev/dsk contains block devices for these disks. Similarly, all volume groups have their own directories in /dev that contain device files for logical volumes. We will see more about logical volumes in Chapter 18. Files starting with tty in the /dev directory represent terminal types.

Almost all of the files in the /dev directory are special files, and if you take a listing with the ll command, you will find a special character in the first column of the output showing whether a file represents a character-type device, block device, or something else. A listing of /dev/rdsk is presented as an example here.

$ ll /dev/rdsk

total 0

crw-r----- 1 bin sys 188 0x003000 Nov 25 1998 c0t3d0

crw-r----- 1 bin sys 188 0x004000 Nov 25 1998 c0t4d0

crw-r----- 1 bin sys 188 0x005000 Nov 25 1998 c0t5d0

crw-r----- 1 bin sys 188 0x006000 Oct 5 16:57 c0t6d0

crw-r----- 1 bin sys 188 0x0a0000 Aug 31 13:40 c10t0d0

crw-r----- 1 bin sys 188 0x0a0100 Aug 31 13:40 c10t0d1

crw-r----- 1 bin sys 188 0x0a0200 Aug 31 13:40 c10t0d2

crw-r----- 1 bin sys 188 0x0a0300 Aug 31 13:40 c10t0d3

crw-r----- 1 bin sys 188 0x0a0400 Aug 31 13:40 c10t0d4

crw-r----- 1 bin sys 188 0x0a0500 Aug 31 13:40 c10t0d5

crw-r----- 1 bin sys 188 0x0a0600 Aug 31 13:40 c10t0d6

crw-r----- 1 bin sys 188 0x0a0700 Aug 31 13:40 c10t0d7

crw-r----- 1 bin sys 188 0x0a1000 Aug 31 13:40 c10t1d0

crw-r----- 1 bin sys 188 0x0a1100 Sep 19 04:58 c10t1d1


As you can see, all of these are character-type devices.

8.4 The /etc Directory

The /etc directory is where a system administrator spends much of his or her time. All of the system configuration files are placed in this directory. The files here control system startup and shutdown procedures as well as the startup and shutdown of server and daemon processes. It also contains configuration files for applications installed on the HP-UX system. The /etc directory also contains subdirectories, as shown in Figure 8-3.

Figure 8-3. The /etc directory hierarchy.

Files in the /etc/rc.config.d directory are configuration and control files for system startup and shutdown and other server and daemon processes.

Files in the /etc/opt directory contain configuration files for applications installed on the system.

8.5 The Home Directory (/home)

Traditionally, this directory contains the home directories of all system users. A home directory for user linda will be /home/linda. All users are owners of their respective directories and have full rights of files under these directories. The size of this directory usually depends on the number of users and varies widely as users add and delete files in their home directories.

Under the home directory of each user is located user-related configuration files. You have already used the $HOME/.profile and $HOME/.exrc files. There may be many other user configuration files. An example would be the file that controls how the X-Window system should start up for a particular user and what should be displayed on the user's desktop.

In a network where user information is shared, the home directories are kept on a central file server and are exported from that server to all other machines. A user can log into any one of the available systems, and he/she will find the same home directory everywhere. At this time, it must also be kept in mind that it is not mandatory to keep all home directories under the /home directory. The system administrator is free to make any choice for home directories. The name /home is just a convention. At the same time, some other directory names are mandatory. For example, a system administrator cannot place system configuration files in a directory other than /etc.

8.6 The System Binary Directory (/sbin)

This directory contains executable files needed at boot time. Under HP-UX, this directory also contains system scripts required at startup and shutdown time. This directory also contains subdirectories. The most important script in the /sbin directory is the rc script that controls all of the system startup and shutdown processes. Another important program is init, which is used to control different system states like single-user mode, multiuser mode, etc. There is the /sbin/init.d directory that contains all scripts executed at system startup and shutdown or at the time when the system changes its state (e.g., from single-user to multiuser). A partial /sbin directory subtree is shown in Figure 8-4.

Figure 8-4. The /sbin directory subtree.

There are directories with names /sbin/rc0.d, /sbin/rc1.d, and so on. These control different runlevels or system states in conjunction with the /sbin/init program. You will find more information on runlevels in Chapter 11 where system startup and shutdown procedures are discussed. Most of the other daemon startup and shutdown scripts are also stored in this directory.

8.7 The /stand Directory

This is the directory where the HP-UX kernel is kept. The kernel configuration file is also present in this directory. The kernel file is /stand/vmunix and the configuration file is /stand/system. In addition, you can keep multiple kernel files in this directory so that if a new kernel fails to boot, you could use any old kernel file to recover such a situation. It also contains the /stand/build directory used to rebuild the new kernel.

8.8 The /net Directory

This is a reserved name for remote file system mount points.

8.9 The Application Directory (/opt)

The /opt directory is used for installing applications on an HP-UX system. Each application has a subdirectory in this directory. Starting from that subdirectory,

each application may have its own directory tree containing binary files, manual pages, libraries, and so forth.

Putting applications in one directory solves many problems related to system administration. Not all vendors that supply software for HP-UX specify a particular directory for their application. This makes it easy to keep multiple versions of the same application on the system, as each version has its own directory structure, which is independent from the rest of the system or any other application. Also, it makes it easy to keep track of these applications when they are installed under one top directory, exactly like it is easy to maintain home directories of users when all of these exist under one main directory /home. You should keep in mind, however, that although application files are kept under this directory, some application files maintain configuration files in /etc/opt and log files in /var/opt directories. This scheme provides another advantage when application directories are shared among many systems on a network, since each sharing system can have its own separate configuration and log files depending on local system configuration.

A sample application directory tree is shown in Figure 8-5 showing the HP Ignite-UX application used for system recovery.

8.10 The Temporary File Directory (/tmp)

This directory has permissions for everybody to create or delete files. Most of the time, temporary files are placed in this directory and are deleted from time to time. Many system administrators prefer to empty this directory at boot time to avoid the piling up of unnecessary files. Anybody creating files in this directory must be aware of the public nature of this directory, and no important file should be placed here. It is a better idea to enable the sticky bit on this directory so that a user may not delete files in this directory created by other users.

Any applications that need to create temporary files should do so in the /var/tmp directory instead of /tmp.

8.11 The /usr Directory

This is an important directory, as most of the HP-UX system files are placed here. This directory contains a number of subdirectories that arrange different types of files. Figure 8-6 shows a partial structure of this directory. The most important file types are user-related commands, libraries, documentation and manual pages, contributed software, and X-Window system files.

Figure 8-6. Structure of the /usr directory.


This directory contains user commands, applications, and utilities.


Contains contributed software from other sources.


Header and include files used for programming.


Libraries for programming and machine-dependent database files. A user may need to look into this directory to check the existence of certain libraries in case there are compilation or run-time errors.


Many system administration commands are placed here.


Manual pages for HP-UX commands.

8.12 The Variable Files Directory (/var)

This directory contains basically three types of files: log files, spool files, and temporary files created by applications. The name of the directory comes from the fact that all of these file types are variable in nature. It means these files grow and shrink on a continual basis. A sample directory subtree is shown in Figure 8-7.

Figure 8-7. Structure of the /var directory.

Log Files

Log files are arranged in many directories depending on the type of log. Some of these are explained here.


This directory is used for log files related to system administration programs. The software installation or removal files are in the /var/adm/sw directory. Log files for cron are placed in the /var/adm/cron directory. Log files generated by syslog are in the /var/adm/syslog directory. Crash dumps are kept in the /var/adm/crash directory.


Application run-time files and log files are placed in this directory.

Spool Files (/var/spool)

Spool files related to print services are kept in the /var/spool/lp directory. Spool files for electronic mail go into /var/mail. Other spool files are kept in a directory under /var/spool.

Temporary var files (/var/tmp)

Temporary files generated by some applications go into the /var/tmp directory. The mail system also keeps its temporary files in the /var/mail directory.

8.13 The lost+found Directory

These files are usually created by the fsck command, which is used to check file system integrity from time to time and at boot time. The files that have no valid links are copied to this directory. Each file system contains one lost+found directory.

Study Break

HP-UX Directory Tree

It is useful to have a look at your HP-UX system at this point. Log into HP-UX and try to construct a three-level directory tree. The first level is the root directory. All

directories under the root directory are placed in the second level. In the third level, list all other directories found inside the directories at the second level.

8.14 Some Useful Commands Related to File System Hierarchy

If you understand file system hierarchy, it will not be difficult for you to find a file in UNIX. However, there are some useful commands to help you in your file search.

The which Command

If you want to find out in which directory an executable file or command is located, you can use the which command. For example, if you want to see in which directory the ls command is located, use the following procedure.

$ which ls



The which command finds all files that are located in your search path.

The whereis Command

Another command is whereis, which can search and locate source, binary, and manual pages. The following command shows two files that can be used as the cat command and the path to the manual page for the command.

$ whereis cat

cat: /sbin/cat /usr/bin/cat /usr/share/man/man1.Z/cat.1


More on the man Command

You can also use the man -k command to search all man pages related to a keyword. The command below searches man pages and shows all commands related to mkdir.

$ man -k mkdir

dosmkdir(1) - make a DOS directory

mkdir(1) - make a directory

mkdir(2) - make a directory file

mkdirp(), rmdirp()(3G) - create, remove directories in a

path nis_server, nis_mkdir, nis_rmdir, nis_servstate,

nis_stats, nis_getservlist, nis_freeservlist,

nis_freetags(3N) - miscellaneous NIS+ functions

nismkdir(1) - create NIS+ directories

stmkdirs(1) - Utility to build Scalable Type

fonts.dir and charsets.

dir files


Before you can use this command, you must create the /usr/share/lib/whatis file using the catman command. This file contains a list of all manual pages, with a short description of each command.

In the above listing generated by the man -k mkdir command, you can see that there is a number specified in parentheses after the name of a command. This number shows the section of the manual pages in which that entry is found. For example, you can see that both sections 1 and 2 contain a manual entry for mkdir. When you use the man mkdir command, the first manual page found by the man command is displayed. If you want to display a particular manual page, you need to specify the section as the argument to the man command. As an example, to display the manual page for mkdir in Section 2, you need to use the man 2 mkdir command instead of man mkdir.

Test Your Knowledge


What can be determined about file name /etc/named.boot?

A. It is an executable program.

B. It is a configuration file.

C. It is a log file.

D. It is a spool file.


The HP-UX file system hierarchy is based on:

A. Berkley distribution (BSD).

B. AT&T SVR4. C. a logical arrangement of files and directories, not based on BSD or


D. a random distribution of files and directories.


Mail files are kept in which directory?

A. /mail

B. /var/spool/mail

C. /home/mail

D. /var/mail


What is true about the lost+found directory?

A. There is only one lost+found directory in a system.

B. There are as many lost+found directories as the number of file systems.

C. Common users create files in this directory if they find any file lost by another user.

D. The system administrator creates files in it that announce the finding of lost files so that a user who lost a file can retrieve it from there.


To find a command in the search path, we use the command:

A. whatis

B. which

C. whois

D. find


Which directory contains programs needed at boot time?

A. /sbin

B. /usr/sbin

C. /startup

D. /etc


The HP-UX kernel is located in:

A. /kernel

B. /var/kernel

C. /usr

D. /stand

No comments:

Post a Comment