Linux File System Hierarchy

Last updated: May 1, 2024 | Emmanuel Oyibo

The way the Linux system organizes files and folders is called the Linux Filesystem Hierarchy Standard (FHS). It’s like a map for your Linux system. Understanding this map is essential because it makes finding files, fixing problems, and adding software much easier.

In this article, we’ll explain the most important parts of the FHS.

A neat image showing Linux File System Hierarchy

You can access the PDF for the Linux File System Hierarchy here.

Root Directory (/)

The root directory, which is represented by a single forward slash (/), sits at the top of the Linux filesystem hierarchy. Every single file and directory on your system stems from the root directory.

It contains several critical subdirectories that house essential system files and configuration.

/bin

The /bin directory houses essential commands-line programs or binaries that are available to all users on the system. These commands come in handy even when the system is running in single-user mode (for maintenance purposes).

Some commonly used commands found within /bin are cat, cp, ls, mv, rm, and more.

/boot

This directory is crucial for the system startup process. It stores the files necessary for the Linux kernel to load and function properly. The kernel is the core of your operating system, responsible for tasks like managing hardware and allocating resources.

Within /boot you’ll find:

  • vmlinuz: The Linux kernel image
  • initrd: The initial RAM disk, which acts as a temporary file system in the early stages of booting
  • Configuration files: These are files used by bootloaders (like GRUB) to manage the startup process

In addition, it’s important to note that messing around in the /boot directory can cause problems with your system booting up, so proceed with caution.

/dev

The /dev directory plays a special role in Linux — it’s where all your hardware devices represented as files. You can think of these files as doorways to physical devices connected to your system.

This unique approach allows you to interact with hardware components (like your hard drive, keyboard, or sound card) as if they were ordinary files.

Some typical device files you’ll find in /dev include:

  • hda, hdb, sda, sdb, etc.: These represents the hard disk and their partitions
  • tty: Represents the terminal device for interacting with the system
  • random: Provides access to random numbers for applications that need them

The /dev directory embodies the Linux philosophy that “everything is a file,” making hardware management simpler and more intuitive.

/etc

You can think of the /etc directory as the control center for your Linux system. It houses a wide variety of system-wide configuration files. These files dictate how your operating system behaves, managing everything from network settings to user accounts.

Some of the significant files you’ll find within the /etc directory include:

  • passwd: Contains usernames, and basic information about user accounts
  • shadow: Stores secure password information (not usually readable by normal users)
  • group: Contains information about user groups on the system
  • hosts: Maps hostnames to IP addresses
  • fstabs: Lists filesystems and their mount points

System administrators spend a good amount of time in the /etc directory, configuring and tweaking system settings.

/home

The /home directory is where ordinary users find their personal haven on a Linux system. Each user typically has their own subdirectory within /home. These home directories are where users store their documents, music, pictures, settings, and other personal files.

By keeping user data separate, the system promotes organization and helps protect critical system files from accidental changes.

/lib

This directory houses shared libraries — chunks of reusable code — that provide essential functions to the programs located in the /bin and /sbin directories.

These libraries help avoid duplication of code, making programs smaller and reducing memory usage. You can think of libraries as building blocks that multiple programs can use.

Key subdirectories within /lib include:

  • lib64: Holds 64-bit libraries (for systems with 64-bit processors)
  • modules: Stores loadable kernel modules (drivers)

/lost+found

The /lost+found directory acts as a safety net for files that get misplaced during unexpected system events like power outages or crashes. The filesystem checker, fsck, uses this directory to store files or file fragments that it manages to recover but can’t figure out where to put back.

Sysadmins often poke around /lost+found to try to restore potentially important files after a system mishap.

/media

This is designed to be a central location for mounting removable media devices like flash drives, external hard drives, CD/DVDs, and even memory cards from cameras.

When you plug in a removable device, the system typically creates a subdirectory within /media and makes the device’s content easily accessible. This standardized approach makes it convenient to work with files on removable storage devices.

/mnt

The /mnt directory is traditionally meant for temporarily mounting filesystems. System administrators use this directory to access filesystems on devices that aren’t part of the standard system setup.

This might include:

  • Network file shares (like an NFS or Samba share)
  • Extra hard drives or partitions not mounted at boot time
  • Filesystems on unusual devices

This directory provides a flexible way to work with filesystems that aren’t always a permanent part of your system.

/opt

This directory is intended for storing add-on software packages. These are software applications that aren’t included as part of your Linux distribution’s core packages.

Often, these packages are self-contained, meaning they install all their files within their own subdirectories under /opt.

For example, if you install a proprietary commercial program, it might place its files under a directory like /opt/<program_name>.

/proc

The /proc directory is a fascinating beast! It’s a “pseudo-filesystem,” meaning it doesn’t actually contain real files stored on your hard drive. Instead, it provides a window into the inner workings of your running Linux system.

The /proc directory is packed with subdirectories and files that reveal real-time information about your system. Some examples include:

  • Individual process directories (like /proc/1234): Each running process gets a directory named after its process ID (PID), containing information about its state and resource usage.
  • /proc/cpuinfo: Provides details about system’s processor(s)
  • /proc/meminfo: Displays information about your system’s memory usage

Sysadmins and developers often use the /proc directory to troubleshoot issues, monitor system performance, and even change certain system settings on the go.

/root

This is the home directory of the root user (superuser). The root user has unlimited administrative power over the Linux system. Just like other users have home directories under /home, the root user’s home directory is at the top level of the filesystem.

However, it’s important to exercise caution when working as the root user. Changes made in this directory can have far-reaching consequences for the entire system.

/run

The /run directory is a relatively newer addition to the filesystem hierarchy. Its purpose is to store volatile system information that’s only relevant to the current running instance of the system.

This includes things like:

  • Process IDs (PIDs): Files that track the IDs of running processes
  • Sockets: Files that enable communication between different processes
  • Locks: Files that prevent multiple programs from modifying the same resource at the same time

The content of /run are typically cleared when the system shuts down. This highlights its role in storing temporary runtime data.

/srv

This directory is designed for “service data” — files specific to the services provided by the Linux system. If you’re running a web server, you might place your website files under /srv/www. Similarly, an email server could store user mailbox data within /srv/mail.

The primary advantage of using /srv is in helping organize your system. By having a dedicated directory for service-related data, you improve system structure and make it easier to manage various services running on your machine.

/sys

Similar to /proc, the /sys directory is a pseudo-filesystem. However, instead of focusing on processes, /sys provides a view into the devices connected to your system.

It presents hardware information in a structured, file-like way, giving sysadmins and developers tools to both gather information and configure certain hardware settings.

For example, you might be able to view battery information for your laptop or just adjust the brightness of your screen by interacting with files within /sys.

/tmp

The /tmp directory is exactly what its name suggests — a location for temporary files. Programs on your system use this directory to store files they might need for a short period.

However, the content of /tmp are usually not preserved across system reboots. In fact, many Linux distributions have processes that automatically clear out /tmp on a regular schedule or at startup.

/usr

This directory is one of the largest in the Linux file system hierarchy. Its primary purpose is to store shareable, read-only data.

You can think of it as the home for many of the programs, libraries, documentation, and other resources that come bundled with your Linux distribution or are installed later on.

Let’s take a look at some key subdirectories within /usr:

  • bin: Contains a vast collection of user-oriented executable programs (commands)
  • local: Traditionally, this is the place for software installed from source or by the system admin, rather than through the distribution’s package manger
  • sbin: Contains essential system admin programs
  • share: Stores a variety of shared data like documentation, icons, and configurations

/var

The /var directory stands for “variable data.” It holds files that are expected to change and grow in size as your system runs.

Some of the common types of files and subdirectories you’ll find within /var include:

  • log: Contains system logs by various services and programs
  • mail: Holds user mailboxes (though this varies across systems)
  • spool: Holds files waiting to be processed, like print queues and email queues.
  • www: Contains files related to a web server, if you’re running one
  • cache: Stores cached data for programs, speeding up access to frequently used information.

Since /var holds data that changes frequently, it’s important to keep an eye on disk space usage within this directory.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment