Table of Contents Link to heading
- Filesystem Hierarchy Standard (FHS)
- Categorising System Directories
- Hierarchy Structure of System Directories
- Organisation Within the Filesystem Hierarchy
Filesystem Hierarchy Standard (FHS) Link to heading
a set of standards that provides a guideline for Linux distributions on how to organise large numbers of files on the filesystem.
This is the homepage of the FHS.
Categorising System Directories Link to heading
Not Shareable | Shareable | |
---|---|---|
Variable | /var/lock | /var/mail |
Static | /etc | /opt |
By Shareability Link to heading
A directory can be categorised as either shareable or not, referring to whether the directory can be shared on a network and used by multiple machines.
To make these classifications, it is often necessary to refer to subdirectories below the top level of directories. For example, the /var directory itself cannot be categorised as either shareable or not shareable, but one of its subdirectories, the /var/mail directory, is shareable. Conversely, the /var/lock directory should not be shareable.
By File Modification Capability Link to heading
The directory is put into a category of having either static files (file contents will not change) or variable files (file contents can change).
Hierarchy Structure of System Directories Link to heading
The second and third hierarchies repeat the pattern of many of the key directories found under the top-level hierarchy. The fourth hierarchy also repeats some of the top-level hierarchy such as lib, opt and tmp.
While the root filesystem and its contents are considered essential or necessary to boot the system, the other hierarchies are deemed non-essential for the boot process. As a result, the root filesystem and its directories may be the only ones available in certain situations like booting into single-user mode - an environment designed for troubleshooting the system.
Top-Level (Root) Hierarchy: / Link to heading
Directory | Contents |
---|---|
/ | The base of the structure, or root of the filesystem, this directory unifies all directories regardless of whether they are local partitions, removable devices or network shares |
/bin | Essential binaries like the ls, cp, and rm commands, and be a part of the root filesystem |
/boot | Files necessary to boot the system, such as the Linux kernel and associated configuration files |
/dev | Files that represent hardware devices and other special files, such as the /dev/null and /dev/zero files |
/etc | Essential host configurations files such as the /etc/hosts or /etc/passwd files |
/home | User home directories |
/lib | Essential libraries to support the executable files in the /bin and /sbin directories |
/lib64 | Essential libraries built for a specific architecture. For example, the /lib64 directory for 64-bit AMD/Intel x86 compatible processors |
/media | Mount point for removable media mounted automatically |
/mnt | Mount point for temporarily mounting filesystems manually |
/opt | Optional third-party software installation location |
/proc | Virtual filesystem for the kernel to report process information, as well as other information |
/root | Home directory of the root user |
/sbin | Essential system binaries primarily used by the root user |
/sys | Virtual filesystem for information about hardware devices connected to the system |
/srv | Location where site-specific services may be hosted |
/tmp | Directory where all users are allowed to create temporary files and that is supposed to be cleared at boot time (but often is not) |
Second-Level Hierarchy: /usr Link to heading
holds non-essential software for multi-user use.
This directory is sometimes shared over the network and mounted as read-only.
Third-Level Hierarchy: /usr/local Link to heading
holds files for software not originating/installed from the distribution.
Often this directory is used for software that is compiled from the source code.
Fourth-Level Hierarchy: /var Link to heading
holds files that change over time (variables).
Directory | Contents |
---|---|
/var/cache | Files used for caching application data |
/var/log | Most log files |
/var/lock | Lock files for shared resources |
/var/spool | Spool files for printing and mail |
/var/tmp | Temporary files to be preserved between reboots |
Organisation Within the Filesystem Hierarchy Link to heading
User Home Directories: /home Link to heading
has a directory underneath it for each user account.
For example, a user sysadmin will have a home directory of /home/sysadmin. Typically, only the user sysadmin will have access to this directory. Without being assigned special permissions on other directories, a user can only create files in their home directory, the /tmp directory, and the /var/tmp directory.
Binary Directories: /bin Link to heading
contain the programs that users and administrators execute to start processes or applications running on the system.
User-Specific Binaries: /usr/bin and /usr/local/bin Link to heading
binary directories that are intended to be used by non-privileged users.
Sometimes third-party software also store their executable files in directories such as:
- /usr/local/application/bin
- /opt/application/bin
In addition, it is not unusual for each user to have their own bin directory located in their home directory (e.g. **/home/sysadmin/bin).
Root-Restricted Binaries: /sbin and /usr/sbin and /usr/local/sbin Link to heading
primarily intended to be used by the system administrator (the root user).
Some third-party administrative applications could also use directories such as:
- /usr/local/application/sbin
- /opt/application/sbin
Depending on the distribution, the PATH variable may not contain all of the possible bin and sbin directories. To execute a command in one of these directories, the directory needs to be included in the PATH variable list, or the user needs to specify the path to the command.
Software Application Directories Link to heading
Unlike the Windows operating system, where applications may have all of their files installed in a single subdirectory under the C:\Program Files directory, applications in Linux may have their files in multiple directories spread out throughout the Linux filesystem.
For Debian-derived distributions, execute the dpkg -L package_name
command to
get the list of file locations. In Red Hat-derived distributions, you can run
the rpm -ql package_name
command for the list of the locations of the files
that belong to that application.
The executable program binary files may go in the /usr/bin directory if they are included with the operating system, or else they may go into the /usr/local/bin or /opt/application/bin directories if they came from a third party.
The data for the application may be stored in one of the following subdirectories:
- /usr/share
- /usr/lib
- /opt/application
- /var/lib
The file related to documentation may be stored in one of the following subdirectories:
- /usr/share/doc
- /usr/share/man
- /usr/share/info
The global configuration files for an application are most likely to be stored in a subdirectory under the /etc directory, while the personalised configuration files (specific for a user) for the application are probably in a hidden subdirectory of the user’s home directory.
Library Directories Link to heading
contain libraries, which are files which contain code that is shared between multiple programs.
Most library file names end in a file extension of .so
, which means shared
object.
Multiple versions of a library may be present because the code may be different within each file even though it may perform similar functions as other versions of the library. One of the reasons that the code may be different, even though it may do the same thing as another library file, is that it is compiled to run on a different kind of processor. For example, it is typical for systems that use code designed for 64-bit Intel/AMD type processors to have both 32-bit libraries and 64-bit libraries.
The libraries that support the essential binary programs found in the /bin and /sbin directories are typically located in either /lib or /lib64.
To support the /usr/bin and /usr/sbin executables, the /usr/lib and /usr/lib64 library directories are typically used.
For supporting applications that are not distributed with the operating system, the /usr/local/lib and /opt/application/lib library directories are frequently used.
Variable Data Directories Link to heading
The /var directory and many of its subdirectories can contain data that changes frequently. If your system is used for email, then either /var/mail or /var/spool/mail is normally used to store users’ email data. If you are printing from your system, then the /var/spool/cups directory is used to store the print jobs temporarily.
Depending on what events are being logged and how much activity is occurring, the system determines how large your log file becomes. On a busy system, there could be a considerable amount of data in the log files. These files are stored in the /var/log directory.
While the log files can be handy for troubleshooting problems, they can cause problems. One major concern for all of these directories is that they can fill up the disk space quickly on an active system. If the /var directory is not a separate partition, then the root filesystem could become full and cause the system to crash.