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. Directories enable you to group files and other directories, allowing you to organize the file system into a modular hierarchy and giving the file-system structure flexablilty and depth. 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 memory of the computer. The i-node number contains the addresses used to locate all the scattered blocks of data associated with a file. The i-node number 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 number 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:
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:
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.
Directories contain files, subdirectories, or a combination of both. A subdirectory is a directory within a directory. The directory containing the subdirectory is called 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.
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 that files do, as explained in File-Naming Conventions .
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 in length.
The file system uses the following kinds of path names:
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.
Two files named 9 can exist 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.
Abbreviations provide a convenient way to specifycertain 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. For more information, see Bourne Shell). |
$HOME | Your home directory (this is true for all shells). |