The Filesystem Hierarchy Standard (FHS) is a set of guidelines that define the structure of the directories and files on a Linux operating system. Understanding the FHS is essential for Linux users, administrators, and developers to effectively manage files, navigate directories, and ensure compatibility across different Linux distributions. This guide provides a comprehensive overview of the FHS, covering its core concepts, main directories, and important subdirectories.
The FHS defines the layout of the directories and files in a Linux system to maintain consistency and ensure interoperability between various distributions. It is maintained by the Linux Foundation and adheres to the POSIX (Portable Operating System Interface) standard. The FHS is beneficial for:
- Organizing system and user files
- Facilitating the installation and maintenance of software
- Ensuring compatibility between distributions
The FHS organizes the Linux file system into a hierarchical structure with the root directory (“/”) at the top. The main directories under the root directory include:
/bin (Essential User Binaries): This directory contains essential user-level binary files, such as commands and utilities, that are required for both single and multi-user environments. Examples include ls, cp, and mv.
/boot (Boot Files): The /boot directory holds files needed for the boot process, such as the bootloader (e.g., GRUB), kernel image, and initial ramdisk (initrd).
/dev (Device Files): This directory contains device files that represent various hardware devices, such as hard drives, terminals, and printers. In Linux, devices are treated as files, allowing users to interact with them using standard file operations.
/etc (System Configuration Files): The /etc directory holds system-wide configuration files and directories. These files are used to configure system behavior, services, and applications.
/home (User Home Directories): This directory contains home directories for individual users. User-specific files, such as personal documents, configurations, and downloads, are stored here.
/lib (Shared Libraries and Kernel Modules): The /lib directory contains shared libraries and kernel modules required by the binaries in /bin and /sbin.
/media (Removable Media): The /media directory is used as a mount point for removable media, such as USB drives, CDs, and DVDs.
/mnt (Temporary Mount Points): This directory is used for temporarily mounting filesystems, such as network shares or external drives.
/opt (Optional Software): The /opt directory is intended for optional or third-party software that doesn’t follow the standard filesystem layout.
/proc (Process Information): The /proc directory is a virtual filesystem that provides information about running processes and the system’s hardware and kernel configuration.
/root (Root User’s Home Directory): This directory serves as the home directory for the root user.
/sbin (System Binaries): The /sbin directory contains essential system-level binaries, such as commands and utilities required for system maintenance and administration.
/srv (Service Data): This directory is used for storing data specific to system services, such as data for web servers, FTP servers, or database servers. The structure of this directory is left up to the system administrator.
/sys (Sysfs Virtual Filesystem): The /sys directory is a virtual filesystem that provides a mechanism for the Linux kernel to export information about devices, drivers, and kernel features to user space. It also allows user space programs to modify kernel settings.
/tmp (Temporary Files): The /tmp directory is used for storing temporary files created by applications and the system. This directory is usually cleared upon system reboot or by a periodic system maintenance script.
/usr (User Binaries, Libraries, and Documentation): The /usr directory contains user-level binaries, libraries, and documentation that are not essential for system booting. It is further subdivided into several subdirectories, including:
- /usr/bin: Contains non-essential user-level binaries
- /usr/sbin: Contains non-essential system-level binaries
- /usr/lib: Contains non-essential shared libraries and kernel modules
- /usr/local: Contains locally-installed software that follows the FHS structure
- /usr/share: Contains architecture-independent data, such as documentation, images, and configuration files
- /usr/src: Contains source code, such as kernel source code and headers
/var (Variable Data Files): The /var directory holds variable data files, such as log files, mail spools, and print queues. Its subdirectories include:
- /var/log: Contains system and application log files
- /var/mail: Contains user mailboxes
- /var/spool: Contains data waiting for processing, such as print jobs and cron jobs
- /var/cache: Contains cached data for applications
- /var/lib: Contains variable state data for applications
- /var/tmp: Contains temporary files that persist across reboots
Understanding the Filesystem Hierarchy Standard (FHS) for Linux is essential for effective file management and system administration. By adhering to this standard, Linux distributions maintain consistency, facilitate software installation and maintenance, and ensure compatibility. Familiarize yourself with the various directories and their purposes to efficiently navigate and manage your Linux system.