Linux Filesystem Hierarchy Standard (FHS) – Structure Overview

The Filesystem Hierarchy Standard (FHS) describes the directory structure and contents in Unix and Unix-like operating systems. It defines where files and directories should be located and what they should contain.

Key Features of FHS:

  • Current Version: The current version is 3.0, released on June 3, 2015, and is maintained by the Free Standards Group.
  • Philosophy: In Unix-like operating systems, everything is considered a file.
  • Adoption: Only Linux distributions follow the FHS, and even then, only partially. Each distribution may have its own policies, resulting in slight differences in directory tree structures across distributions.

Checking the FHS on Your System:

To find information about your system’s FHS, use the following command: man hier and this command displays the directory structure specific to your system.

displays the directory structure - Man hier command in Linux

DirectoryDescription
/binContains essential binary files and command executables that are required for system operation. These files are used by both administrators and regular users to execute commands.
/devContains device-related files, such as hardware devices, RAM, and other system resources. These files allow the system to communicate with physical devices like hard drives, USBs, etc.
/homeContains user directories where local users' personal files and configurations are stored. Each user typically has a subdirectory here.
/lib64Holds 64-bit libraries that support 64-bit applications and programs on the operating system. These libraries are essential for running programs.
/mntUsed to mount temporary storage devices, such as external hard drives, CD/DVDs, or USB drives. It acts as a placeholder for mounted devices.
/procContains process-related files and directories. These files provide real-time information about processes currently running on the system and are directly connected to the kernel.
/runHolds runtime data that is needed during system operation, such as currently running processes, temporary files, and system information.
/srvUsed for service-related files. It contains data that is served by the system, such as web data, FTP servers, or other services.
/tmpStores temporary files. Data placed here is meant to be temporary and will be deleted automatically after a reboot or after a certain period.
/varContains variable data, such as log files, database files, and application data. Logs generated by system processes and applications are stored here.
/bootContains files required for the booting process, such as the Linux bootloader (GRUB) and the vmlinuz kernel file. If the system can't boot with the normal kernel, the rescue kernel is used.
/etcStores configuration and settings files for system-wide settings. Files here control everything from network configuration to software settings.
/libContains 32-bit libraries necessary for running 32-bit applications on the system.
/mediaUsed for mounting removable media such as CD/DVD drives, USB drives, and other external storage devices.
/optTypically used for installing optional or third-party software packages, especially large, self-contained applications.
/rootThe home directory of the root user. It is the default directory for the system's administrator (root).
/sbinContains system binary files and commands that are primarily intended for use by the root user (administrator). Regular users typically don't have access to these commands.
/sysContains system and kernel-related files. It provides a virtual file system for interacting with the kernel and other hardware-related components. It is crucial for system management and monitoring.
/usrContains user programs and data, such as applications, utilities, libraries, and documentation that are not essential for the system's basic operation but are available for regular users.

Overview of the Linux File Hierarchy Structure

The Linux File Hierarchy Structure (FHS) defines the organization of directories and files in Unix-like operating systems. It is maintained by the Linux Foundation and is fundamental to the operation of the system.

The directories in the Linux filesystem hierarchy form the backbone of the operating system. Each directory serves a specific function within the system’s structure, ensuring seamless interaction between the operating system, applications, and users.

Linux File System Structure

In the Linux filesystem hierarchy, all directories fall under the root directory, represented by a forward slash (/). It serves as the starting point for the entire file system hierarchy, encompassing everything in the system, even if files and directories are stored on different physical or virtual devices.

Only the root user (administrator) has permission to write directly under this directory, ensuring system integrity and security.

Linux Root Directory

In the snapshot above, we have displayed the root directory of our Ubuntu system using the command ls /. The forward slash (/) represents the root directory. Directory can be less or more depending on the Linux flavour you are using.

Also Read: Introduction to Linux Operating System: A Comprehensive Guide for Beginners

1. Linux Binary Directory

Binary files contain compiled source code, also known as machine code. They are often referred to as executable files because they can be directly executed by the computer to perform specific tasks.

Key Directories for Binary Files

The Linux filesystem includes several directories that store binary and executable files:

  • /bin
  • /sbin
  • /lib
  • /opt

/bin

The /bin directory is essential for both single-user mode and multi-user environments. It contains user binaries and executable files that are commonly used by all users. Some of the key commands found in /bin include:

  • cat – Concatenate and display files
  • cp – Copy files and directories
  • cd – Change the current directory
  • ls – List directory contents
  • mv – Move or rename files and directories
  • rm – Remove files or directories

Important Note: The /bin directory does not contain any subdirectories. It is solely for executable files that are fundamental to system operations and user activities.

/lib

The /lib directory contains shared libraries and kernel modules essential for the operation of the system. These shared libraries are used by programs and commands stored in the /bin and /sbin directories.

  • Shared Libraries: These are files that provide functionality to other programs, similar to how DLL files work in Windows. Shared libraries are dynamically loaded into memory when needed.
  • Kernel Modules: These are drivers or extensions that allow the Linux kernel to interact with hardware or perform specific tasks.

The shared library files in /lib are easily identifiable by their names, which typically follow these patterns:

  • Start with ld* (e.g., ld-linux.so.2)
  • Start with lib* and include .so.* (e.g., libfuse.so.2.8.6)
/lib32 and /lib64

During the compilation of libraries, you may come across the directories /lib32 and /lib64, which are used to distinguish between libraries compiled for 32-bit and 64-bit systems. These directories clarify which register size should be used during the execution of binaries.

/opt

The /opt directory is short for optional and is primarily used to store optional application software packages. This directory is ideal for software that is not part of the default Linux installation or system package manager.

The /opt directory is designed to house third-party software, ensuring flexibility and organization. It is often empty unless add-on applications are explicitly installed.

2. Configuration Directory

The configuration directory contains files that configure the parameters and initial settings for various computer programs and system operations.

Key Directories for Binary Files

  • /boot
  • /etc

/boot

The /boot directory contains files required to boot the system. These files are essential for initializing a basic Linux system. Files like Bootloader files, such as those for GRUB (Grand Unified Bootloader). Configuration files like /boot/grub/grub.cfg (on older systems, it may be /boot/grub/grub.conf).

Note: Grub Configuration Path /boot/grub/grub.cfg

/etc

The /etc directory holds configuration files specific to your machine. It contains settings for the system and various applications. It stores static and text-based configuration files. Includes startup and shutdown shell scripts used to manage programs. Does not contain binary files.

3. Data Directory

The data directory is used to store various types of system data. It includes directories for user files, server data, removable media, and temporary files.

Key Directories for Binary Files

  • /home
  • /root
  • /media
  • /mnt
  • /tmp

/home

It Stores users’ personal files. Each user has a dedicated subdirectory within /home, named after the username (e.g., /home/username). It contains subdirectories like Desktop, Downloads, Documents, Pictures, etc.

Example: /home/john/Downloads

/root

The /srv directory is short for service. It stores server-specific data for system services like:

  • www (web server data)
  • cvs (version control data)
  • rsync and ftp (file transfer services)

/media

Acts as a mount point for removable media devices. Examples: CD-ROMs, USB drives, external hard drives, etc.

/mnt

It stands for mount. This directory is intended for mounting temporary filesystems. It is generally kept empty by system administrators until required.

/tmp

It stores temporary data, which may use disk space or RAM. Files in /tmp are automatically deleted when the system reboots.

4. Linux Memory Directory

The memory directory contains files that provide access to system-wide information, such as devices, processes, and system-related configurations. These directories do not store actual data but act as virtual filesystems to represent system resources.

Key Directories for Binary Files

  • /dev
  • /proc
  • /sys

/dev

It represents device files. It contains files used to access both physical and virtual devices includes terminal devices, USB devices, and more.

/proc

It contains process-related information. A pseudo-filesystem that provides information about running processes. Contains text files that represent system resources and process details.

/sys

It contains system and hardware configuration files. Provides kernel information about hardware devices.

5. Unix System Resources Directory (/usr)

The /usr directory stands for Unix System Resources and is often pronounced as “user.” It is referred to as the secondary hierarchy because it contains various system resources like binaries, libraries, and documentation for user applications. This directory mainly holds shareable, read-only data.

Key Directories for Binary Files

  • /usr/bin
  • /usr/include
  • /usr/lib
  • /usr/share
  • usr/local
  • usr/src

/usr/bin

It contains non-essential binary commands for all users. It stores executable files that are not required for the system’s basic operation but are commonly used by users.

/usr/include

It contains standard include files for the C programming language. Used by compilers during the compilation process. Stores header files that define the interfaces for system libraries.

/usr/lib

It contains libraries required by system programs. It stores shared libraries that are used by binaries in /usr/bin and /usr/sbin.

/usr/share

It stores architecture-independent data. Contains files that are not dependent on the hardware architecture of the system.

/usr/local

It is used for locally installed software. Software installed from source or third-party applications is typically installed here.

/usr/src

It stores source code. This directory holds the source code for software and system components, including the kernel source code and its associated header files.

6. Variable Directory (/var)

The /var directory is short for variable. It stores files that have an unpredictable size and are expected to change continuously during the normal operation of the system. These files include log files, spool files, and cache files, hence the name “variable.”

Key Directories for Binary Files

  • /var/log
  • /var/cache
  • /var/spool
  • /var/lib

/var/log

It stores system and application log files that record system events, application errors, and other important system information.

/var/cache

It stores cache data generated by applications. Cache files can be safely deleted without losing important data, as they can be regenerated when needed.

/var/spool

It stores files that are waiting to be processed. It contains data for tasks that are queued for processing, such as print jobs, mail queues, and cron jobs.

/var/lib

It stores state information and data files. It contains files that store system and application state information, such as databases or metadata. The files in this directory are frequently modified as the corresponding programs run and update their state.

7. Non-Standard Directories

Non-standard directories are those that do not fall under the standard Filesystem Hierarchy Standard (FHS). These directories are typically specific to certain Linux distributions or applications.

Key Directories for Binary Files

  • /cdrom
  • /run
  • /lost+found

/cdrom

It is used for mounting CD-ROM devices. According to the FHS, CD-ROMs should ideally be mounted under /media instead.

/run

It stores runtime variable data. The /run directory contains data about the system since the last boot. It holds information about running processes, daemons, and other runtime information. This directory is typically cleared when the system reboots.

/lost+found

It stores recovered files after a filesystem check. After a system crash or during a filesystem check (using fsck), lost data that is recovered may be placed in this directory. The recovered data may not always be in usable form and could be fragmented.

Leave a Comment