In their efforts to quickly learn the flashier side of Linux, many administrators are bypassing some of the basics inherent in the Linux structure. What these rebel admins are finding is that eventually they hit “The Wall of Inability.” Without knowing the basic Linux hierarchy, the best that Linux can offer will always be out of reach.
In an effort to right this wrong, I will use this Daily Feature to demystify the Linux directory structure. So without further ado, here are the parts of the Linux directory that you might have missed out on—and here is what you have to look forward to.
The root of everything
In Linux, the term root refers to the superuser of a system. In reference to the directory structure of a Linux system, however, the term root directory refers to the starting point of every single directory and file. The root directory, sometimes referred to as /, is the base of the directory structure. Just as Windows has C:, Linux has /.
From a command prompt, type cd /, and then type pwd (the command used to display the present working directory). The output of pwd will be /—the root directory. You cannot go any deeper than /.
One thing you should pay close attention to is that, unlike the Windows C: directory, in which it is safe to save files, the Linux root directory is structured in a very specific format, and a stray file could cause the partition to be unmountable.
Beyond the root
A number of directories exist beneath / in the Linux hierarchy. Below is a description of the more important directories under /.
The /bin directory is where many of the basic Linux commands are housed. The /bin directory is in all standard user $PATHS, meaning that any executable contained within /bin can be executed from anywhere in the directory structure. The globalization of the /bin directory allows the user to run the ls (and other commands) on current working directories and files.
The /boot directory houses all the boot code for the Linux system. Crucial files are housed within this directory and, unless a kernel recompilation is necessary, it is best not to touch the contents of /boot.
The /dev directory seems to be the biggest mystery to new Linux users. To understand this directory, you need to keep in mind that everything is treated as a file in Linux—even devices such as printers, scanners, and hard drives.
Since everything is a file in Linux, every file needs a centralized location to be housed, and what better place to house device files than the /dev directory?
By running the ls command from within the /dev directory, you will see entries such as audio, cdrom, hda, sda, and ttyS0. Each of these entries represents a possible hardware (or system) device for the machine. For example, on my machine, I know that /dev/hda is the first primary partition on my hard drive.
The /etc directory is a vital part of the Linux system because it contains the majority of the necessary configuration files and resources. Most of these files are saved in text format, so they are editable with any text editor. The permissions of the /etc directory dictate that only the root user can modify the contents. Do not change this permission.
The /home directory houses all the individual user account information as well as the users’ personal files. If a particular Linux system has normal user accounts such as Jack, John, and Jim, then /home will contain directories for each user (named after each respective user).
The /lib directory contains all the shared library files necessary to run the Linux system. These files are all dynamically linked from various places around the hierarchy.
The /lost+found directory contains stray files that have been picked up after a system crash. Typically, after a crash, lost files will appear as numbered files (not as the original filenames).
The /opt directory is simply a location where larger packages (such as StarOffice, OpenOffice, and Applixware) should be installed.
The /proc directory contains virtual files for various processes on a machine such as the CPU, RAM, I/O Ports, and Interrupts.
The /sbin directory contains many applications that are reserved for the root user. The /sbin directory should house any applications that are necessary to start system processes, as well as many of the configuration utilities (such as netconf).
The /tmp directory holds the temporary files that are needed for various applications and processes.
The /usr directory contains a number of very important subdirectories such as:
This directory is like /bin, only it contains more advanced commands and many user-installed commands.
This is where the kernel source is located.
This directory is commonly used to install packages from source.
This directory contains system commands that can be executed only by the system or the root user.
This directory contains the documentation installed on the system.
This directory contains the files used by the man help system.
The /var directory contains system files, such as logs, and often-changing user/system files, such as print spoolers and mail spoolers.
For what it’s worth
The Linux system is based on a very flexible directory structure that allows for many variations on the above descriptions. One variation that many administrators use is to place the more critical directories on their own partitions or even their own drives. Some directories commonly given their own partition are:
By giving /boot its own partition, administering a corrupt system becomes much easier.
By giving /var its own partition, it will be more difficult for an out-of-control log file to slow down a system.
By giving /home its own partition, users are less likely to be able to damage a system (such as filling up the /home directory beyond the 2-gig file limit).
Above are just some examples of how flexible the Linux directory structure can be. By using this flexibility to your advantage, you can create a partitioning scheme for nearly any need.