Understanding the Linux File System Hierarchy - Linux Simplified

Welcome to my Linux Simplified series!

In this post, we're diving into one of the most fundamental concepts of Linux: the Filesystem Hierarchy Standard (FHS).

Filesystem Hierarchy Standard (FHS)

If you are familiar with Windows, you might know that there are partitions named by letters (C:, D:). But Linux organizes everything into a more unified directory tree system called FHS. This tree starts with the root directory (/). Every file, every directory, every device and even the processes are represented as a file under this / directory.

Remember, everything is a file in Linux!

This may sound intimidating at first, but it’s a pretty simple system, and understanding it is really useful for understanding how things work inside IT and infrastructure in general. Because nowadays almost every system runs on Linux. Also, since this is a standard among Linux distros, no matter what Linux distro you’re in, you’ll find files in roughly the same places. This makes it much easier to learn,troubleshoot and manage Linux systems.

Why Is FHS Important?

  • Quickly find files

  • Troubleshoot effectively

  • Correctly install packages

  • Maintaining security


Here's a diagram of the tree hierarchy.

Key Directories

These specific subdirectories have their own purpose.

/ (Root Directory)

  • This is the top level directory of the hierarchy, and everything belongs under this.

/root (Root User’s Home)

  • Root user’s personal directory (similar to /home/username)

/bin (Binaries/Executables)

  • Contains essential user command binaries like mv, cp, ls, cat.

  • Always available to all users.


/sbin (System Binaries)

  • Contains system binaries that are essential for managing and maintaining the system. (mounting, checking, shutting down disks...etc.)

  • Important for troubleshooting.


/lib (Library Files)

  • Similar to DLL files in Windows.

  • These are the shared libraries and kernel modules primarily required by the essential binaries in /bin and /sbin for system boot and core functions.

  • Depending on the system, you’ll find /lib32 and /lib64 directories alongside the /lib directory.


/dev (Devices)

  • All the hardware devices(HDD, CD/DVD, USB..etc) are shown as files.

/mnt (Mount)

  • Contains the manually mounted devices.

  • Useful for system maintenance and recovery situations.


/media (Media)

  • Contains the removable devices as usable files (HDD, CD/DVD, USB).

  • Unlike /mnt , Linux automatically mounts these devices here.


/boot (Boot)

  • Contains all the crucial system files that are required for the system booting.

  • Examples:

    • initrd

    • initramfs

    • GRUB

    • grub.cfg


/etc (Editable Text Configurations)

  • Contains the system-wide configurations (network,user accounts, startup scripts,service config..etc).

  • These are generally static config files, not binaries.

  • Use cases

    • ssh/sshd_config SSH Server Config

    • passwd User Password Config

    • fstab File System Table


/proc (Process Information)

  • This is a virtual file system.

  • Contains the running processes and Linux kernel parameters.

  • Tools like top and ps get the information from here.

  • Monitoring, debugging, and interacting with processes.

    • /proc/meminfo

    • /proc/cpuinfo


/sys (System Information)

  • This is a virtual file system.

  • Shows the drivers, kernel and hardware information.

  • Used by the system utilities.


/usr (Unix System Resource)

  • Contains the system's user programs and utilities, libraries and documentation.

  • These aren’t essential for booting up/repairing the system.

  • Use cases

    • /usr/bin Popular user executable programs like python, git, firefox.

    • /usr/sbin Nonessential sysadmin programs.

    • /usr/lib Libraries for /usr/bin/usr/sbin

    • /usr/local Reserved for locally installed/compiled programs (To avoid any conflicts with system-managed packages)


/var (Variable Data)

  • Contains the variable data files.

  • Use cases

    • /var/log System log files

    • /var/www Default location for web server files (ex: Apache)

    • /var/mail User mailbox

    • /var/tmp Temp files that are kept between reboots (Unlike /tmp)


/run (Runtime Data)

  • Contains the current running data on RAM

  • Starts very early in startup process

  • Replacement for legacy /var/run and /var/lock


/srv (Services)

  • Contains the service related files.

  • Use cases

    • /srv/www Web Server (recommended by FHS instead to /var/www)

    • FTP Server


/home (User Home Directories)

  • Contains the personal directories of regular (non-root) users.

  • Each user has their own directory

    • /home/username1

    • /home/username2

  • Usually a user’s documents, downloads, personal scripts… etc all belong here.


/opt (Optional)

  • Used for optional software packages that aren’t part of the standard system.

  • Most of the time used to install software by third party software vendors.


/tmp (Temporary)

  • Stores the temporary data used by applications and users.

  • Automatically erase all the data after a reboot.

  • Writeable by everyone.


As you might understand now, this FHS provides a logical, consistent format that makes our lives easy to find configuration files, locate logs for troubleshooting, and manage the system more effectively.

Ok, so this is a wrap-up. See you in the next post where I’ll talk about the basic commands in the Linux terminal.

0
Subscribe to my newsletter

Read articles from Dewnuwan Jayaweera directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Dewnuwan Jayaweera
Dewnuwan Jayaweera