Linux Filesystem Hierarchical Standard





Last Updated on 09/16/2019 by dboth

The actual structure of the Linux (or Unix) filesystem, that is the names and layout of the directories in the filesystem, appear to be random and complex. In reality the historical usage and structure has been somewhat random in the past, depending at least in part upon the standards and practices of individual organizations and the specific lineage of the Unix or Linux version in use.

The Importance of Standardization

The primary reason to standardize the directory structure and usage of the Linux filesystem is to make life easier for the system administrator. Knowing where to look for files by usage or type makes one’s life much easier. This is especially true when many different Linux distributions can be running side by side in the same organization. Consistency makes it easier for system administrators to switch between distributions when working.

As a usually very organized Virgo, I like things stored in smaller, organized groups rather than in one big bucket. The use of directories helps me to store and then locate the files I want when I want them. Directories are also known as folders because they can be thought of as folders in which files are kept in a sort of physical desktop analogy.

In Linux, and many other operating systems, directories can be structured in a tree-like hierarchy. The Linux directory structure is well defined and documented in the Linux Filesystem Hierarchy Standard (FHS)1. This standard has been put in place to ensure that all distributions of Linux are consistent in their directory usage. Such consistency makes writing and maintaining shell and compiled programs easier for SysAdmins because the programs, their configuration files, and their data, if any, should be located in the standard directories.

The standard

The latest Filesystem Hierarchical Standard (3.0)2 is defined in a document maintained by the Linux Foundation3. The document is available in multiple formats from their web site, as are historical versions of the FHS. I suggest that you set aside some time and at least scan the entire document in order to better understand the roles played by the many subdirectories of these top-level ones.

Figure 19-2 provides a list of the standard, well known, and defined top-level Linux directories and their purposes. These directories are listed in alphabetical order.

Directory Part of / Description
/ (root filesystem) Yes The root filesystem is the top-level directory of the filesystem. It must contain all of the files required to boot the Linux system before other filesystems are mounted. After the system is booted, all other filesystems are mounted on standard, well defined, mount points as subdirectories of the root filesystem.
/bin Yes The /bin directory contains user executable files.4
/boot No Contains the static bootloader and kernel executable and configuration files required to boot a Linux computer.
/dev Yes This directory contains the device files for every hardware device attached to the system. These are not device drivers, rather they are files that represent each device on the computer and facilitate access to those devices.
/etc Yes Contains a wide variety of system configuration files for the host computer.
/home No Home directory storage for user files. Each user has a subdirectory in /home.
/lib Yes Contains shared library files that are required to boot the system.
/media No A place to mount external removable media devices such as USB thumb drives that may be connected to the host.
/mnt No A temporary mountpoint for regular filesystems (as in not removable media) that can be used while the administrator is repairing or working on a filesystem.
/opt No Optional files such as vendor supplied application programs should be located here.
/proc Virtual Virtual filesystem used to expose access to internal kernel information and editable tuning parameters.
/root Yes This is not the root (/) filesystem. It is the home directory for the root user.
/sbin Yes System binary files. These are executables used for system administration.
/selinux Virtual This filesystem is only used when SELinux is enabled.
/sys Virtual This virtual filesystem contains information about the USB and PCI busses and the devices attached to each.
/tmp No Temporary directory. Used by the operating system and many programs to store temporary files. Users may also store files here temporarily. Note that files stored here may be deleted at any time without prior notice.
/usr No These are shareable, read only files including executable binaries and libraries, man[ual] files, and other types of documentation.
/usr/local No These are typically shell programs or compiled programs and their supporting configuration files that are written locally and used by the SysAdmin or other users of the host.
/var No Variable data files are stored here. This can include things like log files, MySQL and other database files, web server data files, email inboxes, and much more.

Figure 19-2: The top level of the Linux Filesystem Hierarchical Standard.

The directories shown in Figure 19-2, along with their subdirectories, that have a Yes in column 2 are considered to be an integral part of the root filesystem. That is, they cannot be created as a separate filesystem and mounted at startup time. This is because they, specifically their contents, must be present at boot time in order for the system to boot properly. The /media and /mnt directories are part of the root filesystem, but they should never contain any data. Rather, they are simply temporary mount points.

The rest of the directories do not need to be present during the boot sequence, but will be mounted later, during the startup sequence that prepares the host to perform useful work.

Wikipedia also has a good description of the FHS5. This standard should be followed as closely as possible to ensure operational and functional consistency. Regardless of the filesystem types, i.e., EXT4, XFS, etc., used on a host, this hierarchical directory structure is the same.

Resources

1Linux Foundation, Linux Filesystem Hierarchical Standard, http://refspecs.linuxfoundation.org/fhs.shtml

2 http://refspecs.linuxfoundation.org/fhs.shtml

3 The Linux Foundation maintains documents defining many Linux standards. It also sponsors the work of Linus Torvalds.

4Note that /bin and /sbin are now just links to /usr/bin and /usr/sbin, respectively. They are no longer generally split into “essential” and “non-essential” as they used to be.

5Wikipedia, Filesystem Hierarchy Standard, https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard