[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
System User's Guide: Operating System and Devices

Directory Overview

A directory is a unique type of file that contains only the information needed to access files or other directories. As a result, a directory occupies less space than other types of files. It also gives the file system structure flexibility and depth. Directories enable you to group files and other directories, allowing you to organize the file system into a modular hierarchy. Unlike other types of files, a special set of commands control directories.

Directories contain directory entries. Each entry contains a file or subdirectory name and an index node reference number (i-node number). To increase speed and enhance use of disk space, the data in a file is stored at various locations in the computer's memory. The i-node contains the addresses used to locate all the scattered blocks of data associated with a file. The i-node also records other information about the file including time of modification and access, access modes, number of links, file owner, and file type. It is possible to link several names for a file to the same i-node by creating directory entries with the ln command.

Because directories often contain information that should not be available to all users of the system, directory access can be protected. By setting a directory's permissions, you can control who has access to the directory, also determining which users (if any) can alter information within the directory. See File and Directory Access Modes for more information.

This section discusses:

Types of Directories

Directories can be defined by the operating system, the system administrator, or users. The system-defined directories contain specific kinds of system files, such as commands. At the top of the file system hierarchy is the system-defined /(root) directory. The /(root) directory usually contains the following standard system-related directories:

/dev Contains special files for I/O devices.
/etc Contains files for system initialization and system management.
/home Contains login directories for the system users.
/tmp Contains files that are temporary and can be deleted in a specified number of days.
/usr Contains the lpp, include, and other system directories.
/usr/bin Contains user executable programs.

Some directories, such as your login or home directory ($HOME), are defined and customized by the system administrator. When you log in to the operating system, the login directory is the current directory.

Directories that you create are called user-defined directories. These directories help you organize and maintain your files.

Directory Organization

Directories contain files, subdirectories, or a combination of both. A subdirectory is a directory within a directory. The directory containing the subdirectory is the parent directory.

For the operating system to track and find directories, each directory has an entry for the parent directory in which it was created, .. (dot dot), and an entry for the directory itself, . (dot). In most directory listings, these files are hidden.

Directory Tree

Structures of parent directories, subdirectories, and files are called file systems. Directory structures are often compared to an inverted tree. The root directory, symbolized by a / (slash), is the base and pictured at the top of the directory tree. Subdirectories and files branch downward from the root directory.

The file system structure of directories can easily become complex. Attempt to keep the file and directory structure as simple as possible. Also, create files and directories with easily recognizable names. This makes working with files easier.

Parent Directory

Each directory, except for /(root), has one parent directory and may have one or more child directories. In the Example of Directory Structures illustration, C is parent to E, and C is child to /(root).

Home Directory

When you log in, the system puts you in a directory called your home directory or login directory. This directory is set up by the system administrator for each user. Your home directory is where you keep your personal files. Normally, directories you create for your own use will be subdirectories of your home directory. To return to your home directory at any time, enter the cd command at the prompt.

Working Directory

You are always working within a directory. Whichever directory you are currently working in is called your current or working directory. The pwd (present working directory) command reports the name of your working directory. The cd command allows you to change working directories.

Directory Naming Conventions

The name of each directory must be unique within the directory where it is stored. This ensures that the directory also has a unique path name in the file system. Directories follow the same naming conventions as files as explained in File Naming Conventions .

Directory Path Names

Each file and directory can be reached by a unique path, known as the path name, through the file system tree structure. The path name specifies the location of a directory or file within the file system.

Note: Path names cannot exceed 1023 characters.

The file system uses two kinds of path names:

absolute path names Traces the path from the /(root) directory. Absolute path names always begin with the / (slash) symbol.
relative path name Traces the path from the current directory through its parent or its subdirectories and files.

An absolute path name represents the complete name of a directory or file from the /(root) directory downward. Regardless of where you are working in the file system, you can always find a directory or file by specifying its absolute path name. Absolute path names start with a / (slash), the symbol representing the root directory. The path name /A/D/9 is the absolute path name for 9. The first / (slash) represents the /(root) directory, which is the starting place for the search. The remainder of the path name directs the search to A, then to D, and finally to 9.

There are two files named 9. This is possible because the absolute path names to the files give each file a unique name within the file system. The path names /A/D/9 and /C/E/G/9 specify two unique files named 9.

Unlike full path names, relative path names specify a directory or file based on the current working directory. For relative path names, you can use the notation .. (dot dot) to move upward in the file system hierarchy. The .. (dot dot) represents the parent directory. Because relative path names specify a path starting in the current directory, they do not begin with a / (slash). Relative path names are used to specify the name of a file in the current directory or the path name of a file or directory above or below the level of the current directory in the file system. If D is the current directory, the relative path name for accessing 10 is F/10, but the absolute path name is always /A/D/F/10. Also, the relative path name for accessing 3 is ../../B/3.

You can also represent the name of the current directory by using the notation . (dot). The . (dot) notation is commonly used when running programs that read the current directory name.

Directory Abbreviations

Abbreviations provide a quick and convenient way for specifying certain directories. The following is a list of abbreviations.

Abbreviation Meaning
. The current working directory.
.. The directory above the current working directory (the parent directory).
~ Your home directory (this is not true for the Bourne shell).
$HOME Your home directory (this is true for all shells).

Related Information

Commands Overview

Processes Overview

Input and Output Redirection Overview

File Systems Overview

Files Overview

Linking Files and Directories

Backup Files and Storage Media

File and System Security


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]