thelinuxvault blog

Understanding the Linux File Hierarchy Structure

The Linux File Hierarchy Structure (FHS) is a standardized way of organizing files and directories in a Linux system. It provides a consistent layout that helps users, administrators, and software developers know where to find specific types of files. Whether you're a beginner exploring Linux for the first time or an experienced user looking to deepen your understanding, grasping the FHS is crucial for efficient system management and software usage.

2026-06

Table of Contents#

  1. Root Directory (/)
  2. /bin and /sbin Directories
  3. /boot Directory
  4. /dev Directory
  5. /etc Directory
  6. /home Directory
  7. /lib and /lib64 Directories
  8. /media and /mnt Directories
  9. /opt Directory
  10. /proc Directory
  11. /root Directory
  12. /run Directory
  13. /srv Directory
  14. /sys Directory
  15. /tmp Directory
  16. /usr Directory
  17. /var Directory

1. Root Directory (/)#

The root directory is the top - level directory in the Linux file system. It contains all other directories and files. It's like the "base" of a tree, with everything else branching out from it.

2. /bin and /sbin Directories#

  • /bin:
    • This directory contains binary (executable) files that are essential for system operation and are available to all users. For example, common commands like ls, cd, echo are located here.
    • Example Usage: When you type ls in the terminal, the system looks for the ls binary in /bin (or other relevant directories in the PATH variable).
  • /sbin:
    • Holds system - administration binary files. These are usually only accessible to the root user. Commands like shutdown, reboot, fdisk (for disk partitioning) are in /sbin.
    • Best Practice: Only use commands from /sbin when you know what you're doing as they can have a significant impact on the system.

3. /boot Directory#

  • Stores files necessary for booting the system, such as the Linux kernel (vmlinuz), initial ramdisk images (initrd or initramfs), and boot loader configuration files (e.g., GRUB configuration files).
  • Common Practice: Don't modify files in /boot unless you are performing a system upgrade or customizing the boot process.

4. /dev Directory#

  • Represents device files. In Linux, everything is a file, and devices (like hard drives, USB drives, printers) are accessed through special files in /dev. For example, /dev/sda might be the first hard disk, and /dev/tty is the terminal device.
  • Example Usage: When you want to access a USB drive, the system will create a device file (e.g., /dev/sdb1 for a partition on the USB drive) when it's plugged in.

5. /etc Directory#

  • Contains configuration files for system and applications. This is a crucial directory. Files like /etc/passwd (user account information), /etc/group (group information), /etc/network/interfaces (network configuration) are here.
  • Best Practice: Make backups of important configuration files before making changes. For example, before changing the network configuration in /etc/network/interfaces, copy the original file.

6. /home Directory#

  • Each user's home directory is located here. For example, if there is a user named john, their home directory is /home/john. Users can store their personal files, documents, and configuration files (in hidden sub - directories like .bashrc for shell configuration).
  • Common Practice: Encourage users to store their data in their home directories for better organization.

7. /lib and /lib64 Directories#

  • /lib:
    • Holds shared library files that are used by binaries in /bin and /sbin. These libraries provide functions that multiple programs can use. For example, the C library (libc.so).
  • /lib64:
    • On 64 - bit systems, stores 64 - bit shared libraries.

8. /media and /mnt Directories#

  • /media:
    • Automatically mounts removable media (like CDs, DVDs, USB drives) when they are inserted. For example, a CD might be mounted at /media/cdrom.
  • /mnt:
    • Traditionally used for manual mounting of filesystems. You can mount a remote filesystem (e.g., via NFS) or an additional local partition here.
    • Example Usage: mount /dev/sdb1 /mnt/usb (mounts a USB drive partition to /mnt/usb).

9. /opt Directory#

  • Intended for the installation of third - party software packages. Some applications may install their files here. For example, a proprietary software might be installed in /opt/software_name.
  • Best Practice: Check the documentation of the software to see if it follows the FHS for installation in /opt.

10. /proc Directory#

  • A virtual filesystem that provides information about running processes and system resources. Files in /proc are not real files on disk but are generated on - the - fly. For example, /proc/cpuinfo shows CPU information, and /proc/meminfo shows memory information.
  • Example Usage: cat /proc/cpuinfo to view CPU details.

11. /root Directory#

  • The home directory of the root user. It contains configuration files specific to the root user and is separate from the regular user home directories in /home.

12. /run Directory#

  • Holds runtime files, such as process ID (PID) files. These files are created and removed as processes start and stop. For example, a web server might create a PID file in /run when it starts.

13. /srv Directory#

  • Used to store data for services provided by the system. For example, a web server might store its website data in /srv/www.

14. /sys Directory#

  • Another virtual filesystem that provides information about the system's hardware and device drivers. Similar to /proc, but more focused on hardware - related information.

15. /tmp Directory#

  • A temporary storage area. Files in /tmp are usually deleted when the system is rebooted (although some configurations may change this). Applications use /tmp to store temporary files. For example, a text editor might save a temporary file here if the user hasn't saved the main file yet.
  • Best Practice: Don't rely on /tmp for long - term storage.

16. /usr Directory#

  • Stands for "Unix Software Resource". It contains user - accessible programs, libraries, documentation, and more.
    • /usr/bin: Holds user - level binary files (more than /bin).
    • /usr/sbin: System administration binaries (more than /sbin).
    • /usr/lib and /usr/lib64: Similar to /lib and /lib64 but for a wider range of applications.
    • /usr/share: Stores shared data like man pages (in /usr/share/man), fonts, and application - specific data.
    • /usr/src: Can hold source code, especially for the Linux kernel (if you are compiling a custom kernel).

17. /var Directory#

  • Holds variable data, such as log files (/var/log), spool files (for printing, email), and cache files. Log files in /var/log (e.g., /var/log/syslog which records system messages) are crucial for debugging.
  • Best Practice: Regularly check log files in /var/log for any error messages.

Reference#