| < Day Day Up > |
Linux organizes files into a hierarchically connected set of directories. Each directory may contain either files or other directories. In this respect, directories perform two important functions. A
directory
holds files, much like files held in a file drawer, and a directory connects to other directories, much as a branch in a tree is connected to other branches. With respect to files, directories appear to
Because of the similarities to a tree, such a structure is often referred to as a tree structure. This structure could more accurately be thought of as an upside-down bush rather than a tree, however, because no trunk exists. The tree is represented upside down, with the root at the top. Extending down from the root are the branches. Each branch grows out of only one branch, but it can have many lower branches. In this respect, it can be said to have a parent/child structure. In the same way, each directory is itself a subdirectory of one other directory. Each directory may contain many subdirectories but is itself the child of only one parent directory.
The Linux file structure branches into several directories beginning with a root directory,
/
. Within the root directory several system, directories contain files and programs that are features of the Linux system. The root directory also contains a directory called
home
that contains the home directories of all the users in the system. Each
Figure 10-2:
The Linux file structure beginning at the root directory
| Note |
The user's home directory can be any directory, though it is usually the directory that bears the user's login
|
When you log in to the system, you are placed within your home directory. The name given to this directory by the system is the same as your login name. Any files you create when you first log in are organized within your home directory. Within your home directory, however, you can create more directories. You can then change to these directories and store files in them. The same is true for other users on the system. Each user has his own home directory, identified by the appropriate login name. Users, in turn, can create their own directories.
You can access a directory either through its name or by making it the default directory. Each directory is given a name when it is created. You can use this name in file operations to access files in that directory. You can also make the directory your default directory. If you do not use any directory
When you log in, the working directory is your home directory, usually having the same name as your login name. You can change the working directory by using the
cd
command to
The name you give to a directory or file when you create it is not its full name. The full name of a directory is its
pathname.
The hierarchically nested relationship among directories forms paths, and these paths can be used to identify and reference any directory or file unambiguously. In Figure 10-3, a
Figure 10-3:
Directory pathnames
In Linux, you write a pathname by listing each directory in the path separated by a forward slash. A slash
Pathnames may be absolute or relative. An absolute pathname is the complete pathname of a file or directory beginning with the root directory. A relative pathname begins from your working directory; it is the path of a file relative to your working directory. The working directory is the one you are currently operating in. Using the directory structure described in Figure 10-3, if chris is your working directory, the relative pathname for the file monday is reports/monday . The absolute pathname for monday is /home/chris/reports/monday .
The absolute pathname from the root to your home directory could be
$ pwd /home/chris/letters /thankyou $ cat ~/weather raining and warm $
You must specify the rest of the path from your home directory. In the next example, the user references the monday file in the reports directory. The tilde represents the path to the user's home directory, /home/chris , and then the rest of the path to the monday file is specified.
$ cat ~/reports/monday
The root directory that begins the Linux file structure contains several system directories. The system directories contain files and programs used to run and maintain the system. Many contain other subdirectories with programs for executing specific features of Linux. For example, the directory /usr/bin contains the various Linux commands that users execute, such as cp and mv . The directory /bin holds interfaces with different system devices, such as the printer or the terminal. Table 10-1 lists the basic system directories.
|
Directory |
Function |
|---|---|
|
/ |
Begins the file system structure, called the root |
|
/home |
Contains users' home directories |
|
/bin |
Holds all the standard commands and utility programs |
|
/usr |
Holds those files and commands used by the system; this directory breaks down into several subdirectories |
|
/usr/bin |
Holds user-oriented commands and utility programs |
|
/usr/sbin |
Holds system administration commands |
|
/usr/lib |
Holds libraries for programming languages |
|
/usr/share/doc |
Holds Linux documentation |
|
/usr/share/man |
Holds the online manual Man files |
|
/var/spool |
Holds spooled files, such as those generated for printing jobs and network transfers |
|
/sbin |
Holds system administration commands for booting the system |
|
/var |
Holds files that vary, such as mailbox files |
|
/dev |
Holds file interfaces for devices such as the terminals and printers |
|
/etc |
Holds system configuration files and any other system files |
| Note |
The overall organization of the Linux file structure for system directories and other useful directories such as those used for the kernel are discussed in detail in Chapter 33. |
| < Day Day Up > |