Filesystem Hierarchy in Linux

Linux Filesystem follows a tree-like hierarchical layout that is governed by the Filesystem Hierarchy Standard (FHS). This is a standard maintained by the Linux Foundation. The latest version of the FHS at the time of writing this guide is version 3.0.3 which was released in June 2015.

The Linux Filesystem structure starts at the very top with the root directory which is the uppermost directory in the hierarchy. It contains all the directories and subdirectories on the system as we shall see later on in this guide.

To get a better picture of this, navigate to the root directory / and run the following command:

The output provides all the main directories residing on the system. Before we delve deeper and explore what each of these directories contain, let us briefly look at the main types of files on a Linux system.

Type of Files in Linux

In Linux and UNIX systems, everything is considered a file. If not, then it’s a running process. Generally, all files in Linux fall into either of these three categories.

  • Regular files: These include text files, photos, videos, programs, and executable files.
  • Directories: This might sound a bit strange, but in Linux, directories are also considered files since they provide storage for other files and subdirectories.
  • Special files: These are device files that comprise symbolic links, block files, socket files, and named pipe files.

That said, let us now examine the Linux File System Tree in more detail.

/ ( Root Directory)

Denoted by a single forward slash ( / ), the root directory is the topmost directory in the Linux hierarchy structure, as discussed earlier. All files and folders on your Linux system are stored here and can be referenced from this directory, even when stored in various locations such as removable or virtual devices.

NOTE:

The root (/) directory is not to be confused with the root home directory ( /root ).

/home

The /home directory is a directory that contains users’ personal files. The directory is the entry point for any login user on the Linux system. It stores folders, files, and personal data that is specific to an individual user.

Folders in the /home directory take the form /home/USERNAME where USERNAME is the name of the login user. For example, if we have a login user called mike, the home directory for the user will be /home/mike.

Inside the /home/USERNAME directory are other sub-directories such as Desktop, Downloads, Documents, Pictures, Videos, Templates, Public, and Music as below.

In addition, home directories contain personalized configuration files which are hidden files preceded by a dot. Such files include the .bashrc.bash_logout, and .bash_profile to mention a few. To view hidden files, run the ls command with the -la option as shown.

/root

This is the home directory of the root account, also known as the root user’s home directory. The /root directory stores configuration files for the root account in the same way each regular user’s home directory contains configuration files and regular files for that user.

/boot

Another critical directory is the /boot directory. The directory, as the name implies, contains essential files needed to successfully boot the system. These files include the grub bootloader files, root filesystem files, Linux kernel files (vmlinuz), and other boot configuration files

/bin

The /bin directory contains binary executables or Linux programs. These include common Linux commands that are made available for all users in single-user mode. These include cat, chown, chmod, ping, cp, mkdir, ls, cat, rm, and mv just to mention a few.

To confirm the path of a binary executable or command such as the cp command, run the command:

/sbin

Unlike the /bin directory, the /sbin directory contains binary executables and command line tools that are preserved for the root user. These are privileged commands used for system administration tasks. Examples of such commands include fdisk, route, reboot, mkfs, init, and fsck to mention a few.

Again, to confirm the path to the binary executable, run the which command followed by the binary executable.

/dev

The /dev directory contains special files that are representative of devices attached to the system. These include consoles, hard drives, or any other peripheral devices plugged into the system. A good example of a device file is /dev/sda which represents the first SATA hard drive attached to the Linux system.

The /dev directory is also a storage location for pseudo devices or virtual devices that do not reference any hardware connected to the system. An example is the /dev/null file which discards any data sent to it.

/etc

The /etc directory contains host-specific system-wide configuration files. It stores configuration files required by all programs as well as startup and shutdown shell scripts.

The configuration files can be modified using a text editor such as nano or vim by the root or sudo user which is a regular user with elevated privileges to run certain root commands.

/lib,/lib64

The /lib directory contains shared library images required in the /bin or /sbin directories. These are essential libraries required by the system to boot and run normally.

/media

The /media directory contains temporary sub-directories on which removable media such as optical drives are automatically mounted. A good example of a sub-directory is /media/cdrom for optical drives.

/mnt

The /mnt directory provides a temporary mount point on which removable media such as CDROMs can be mounted. It is most often used to mount storage devices or partitions manually, and is more of a relic of the past.

/tmp

On Linux systems, temporary files are stored in the /tmp directory. These are temporary files created by the system and users. Files in this directory are usually a few kilobytes in size and are, in most cases, deleted when a system is rebooted.

/opt

The /opt directory contains add-on applications or software packages that are provided by a third-party vendor and are not installed through your operating system package manager. Each such application has its own subdirectory which contains all the essential files needed for it to run.

When you install a software package from a third-party repository, or compile software binaries yourself, the files are stored in the /opt directory.

/var

Var stands for variable. As the name suggests the /var directory is a directory that contains files that are constantly changing in size such as log and spool files.

Here is a list of the salient directories contained in the /var directory:

  • /var/log – Contains system and application log files.

  • /var/cache – Contains cached data from programs.

  • /var/mail – Contains users’ mailboxes

  • /var/spool – Comprises queued or spooled files for various programs.

  • /var/spool/cron – Contains spooled files for cron jobs.

  • /var/spool/at – Contains spooled jobs for at.

  • /var/spool/lpd – Contains spooled files for printing.

  • /var/opt – Contains variable data files for the /opt directory.

/run

Most Linux distributions come with the /run filesystem. This is a directory that stores volatile runtime data since the system was started. Data stored in this directory does not persist upon a reboot.

/proc

Also referred to as the proc filesystem, The /proc directory is a virtual or pseudo filesystem that contains special files that provide information about running processes and the kernel’s current state. It is regarded as the information and control center of the Linux kernel.

The proc directory is a peculiar directory in that it’s not a real filesystem and it ceases to exist once the system is powered off. It is mounted at the /proc mount point during the booting process.

/usr

This is one of the most critical directories in the Linux system. The /usr directory is a directory that comprises libraries, binaries, and documentation for installed software applications. System files contained in this directory are shareable among other users.

At a glance, here are some of the salient subdirectories contained in the /usr directory:

  • /usr/bin– This contains binary files for user programs that cannot be found under the /bin directories. Examples of such programs include less, more, scp, and awk to mention a few.

  • /usr/sbin – This provides binary files for system administrators or privileged users. Usually, system binaries are located in the /sbin directory but if you can’t find them there, look under the /sbin directory.

  • /usr/local – The directory contains user programs installed from source or outside the distribution’s provided software. For example, when you install the Go programming language from source, it goes under the /usr/local/go directory.

  • /usr/lib – This provided libraries needed by the /usr/bin and /usr/sbin directories.

  • /usr/src– This contains the Linux header files, kernel sources, and documentation.

/srv (Service directory)

The term srv stands for service. The/srvdirectory contains site-specific data for your Linux distribution. It points to the location for data files for a specific service such as www, rsync, FTP and CVS.

/sys

This is a virtual or pseudo filesystem that contains a collection of virtual files that are attached to the Linux Kernel.

/snap

This is where snap packages go into. Snap is a package management system developed by Canonical, the publisher and maintainer of Ubuntu. Snaps are containerized, cross-distribution software packages that are packaged with all their dependencies. They are easy to install and are intended to work across all major Linux distributions that have snap enabled.

If you have installed an application from a snap package, then all the software files will be found in the /snap directory.

/lost+found

This is a directory that is mostly found in Ubuntu and Ubuntu-based distributions. It’s a special directory that contains obsoleted data. These are fragments of files that have either been deleted or lost during disk operation.

The Linux filesystem is a hierarchical directory structure used by the operating system to store and organize files. It is built on a tree structure where the root directory (denoted as /) is at the top, and all other files and directories branch off from it. Here’s an overview of the main components of a typical Linux filesystem:

1. Root Directory (/)

  • The root directory is the starting point for all file paths in the Linux system. All other files and directories are contained within it.

2. Common Directories in the Linux Filesystem:

  • /bin: Contains essential binary executables (programs) required for the system to function. These are often required for troubleshooting, as they are available even when other filesystems are not mounted.

    • Example: ls, cp, mv
  • /boot: Contains bootloader files and kernel-related files necessary for starting the system. This includes files like the kernel image (vmlinuz) and the bootloader configuration (grub).

    • Example: vmlinuz, grub/
  • /dev: Contains device files, which represent hardware and virtual devices on the system. Each device, like a hard drive or USB stick, is represented by a file here.

    • Example: /dev/sda, /dev/tty0
  • /etc: Contains system-wide configuration files and scripts for configuring the system and applications.

    • Example: /etc/passwd, /etc/fstab
  • /home: The directory where user-specific files and directories are stored. Each user on the system has a subdirectory under /home (e.g., /home/user1, /home/user2).

    • Example: /home/john, /home/admin
  • /lib: Contains shared libraries and kernel modules required to run programs stored in /bin and /sbin. These are essential for system operations.

    • Example: /lib/x86_64-linux-gnu/
  • /media: This is where removable media such as USB drives, CD-ROMs, and external hard drives are mounted automatically.

    • Example: /media/usb, /media/cdrom
  • /mnt: A temporary mount point used for mounting filesystems. Often used by system administrators to mount filesystems manually for maintenance or other tasks.

    • Example: /mnt/data
  • /opt: Used for installing optional or third-party software. This directory is typically used for large applications or packages that don’t conform to the standard Linux filesystem hierarchy.

    • Example: /opt/google/chrome
  • /proc: A virtual filesystem that contains runtime information about the kernel and processes. It does not correspond to actual disk storage but provides insight into system and process states.

    • Example: /proc/cpuinfo, /proc/meminfo
  • /root: The home directory of the root user (superuser). Unlike /home, which stores regular user directories, /root is dedicated to administrative tasks.

    • Example: /root/
  • /run: Contains runtime data, such as information about the system’s state, services, and temporary files that should not persist across reboots.

    • Example: /run/user/
  • /sbin: Contains system binaries required for system administration tasks. These programs are typically executed by the system administrator (root).

    • Example: ifconfig, shutdown, fsck
  • /srv: Contains data for services provided by the system. This could include files served by a web server, FTP server, or other services.

    • Example: /srv/www/
  • /sys: Another virtual filesystem that provides information and controls for the kernel, such as hardware details, system status, and device management.

    • Example: /sys/class/net/eth0
  • /tmp: A temporary directory used by programs to store temporary files. Files in this directory are usually deleted when the system reboots.

    • Example: /tmp/file123
  • /usr: Contains user-related programs, libraries, and documentation. This is the largest directory on most systems and is further divided into subdirectories like /usr/bin for executable files, /usr/lib for libraries, and /usr/share for shared data.

    • Example: /usr/bin/bash, /usr/lib/python3/
  • /var: Contains variable files, such as logs, databases, email, and spool files. Files in /var change frequently and can grow in size.

    • Example: /var/log/, /var/mail/

3. Mounting and Filesystem Types

Linux supports different types of filesystems, which can be mounted in various directories. Some common filesystem types include:

  • ext4: A common, modern filesystem for Linux, providing journaling and good performance.
  • xfs: Another high-performance filesystem used often for large-scale data storage.
  • ntfs: A filesystem used by Windows, which can be accessed and mounted on Linux.
  • vfat: A FAT filesystem commonly used for USB drives and memory cards.
  • btrfs: A newer filesystem that supports advanced features like snapshots and data integrity.

4. Filesystem Permissions

Each file and directory in the Linux filesystem has associated permissions that control who can read, write, or execute them. These permissions are granted to three types of users:

  • Owner: The user who owns the file or directory.
  • Group: A group of users who share the same permissions.
  • Others: All other users on the system.

Permissions are typically displayed using a string like rwxr-xr-x, where:

  • r = read permission
  • w = write permission
  • x = execute permission

5. Filesystem Hierarchy Standard (FHS)

The Filesystem Hierarchy Standard (FHS) is a specification that defines the directory structure and directory contents in Linux systems. It provides a consistent structure across distributions, making it easier for users and administrators to understand where files are located.

Conclusion

The Linux filesystem is designed to be highly modular and flexible, with different directories serving specific purposes. It is important for both system administrators and users to understand the structure in order to effectively manage the system.

What Is Linux File System?

The Linux file system is a method of organizing and managing files on a Linux-based operating system. It defines how to store, access, and retrieve data on the disk. Files are arranged in a hierarchical directory tree starting with the root directory (/), which branches into subdirectories and files.

Linux supports various file system types, such as ext4, XFS, Btrfs, and ZFS, each offering different features like journaling, scalability, and snapshot capabilities. The most commonly used file system on Linux is ext4, known for its balance between performance and reliability.

 

Linux has evolved from the limited Minix system to more advanced options like extext2, and ext3. Each version improved file management and storage capabilities, with ext3 adding journaling for better data integrity.

Today, ext4 is the default Linux file system, offering faster performance, larger file support, and improved reliability for modern usage. The following graph shows the ext4 system evolution:

The key directories in Linux include:

  • /home – user data.
  • /var – variable data, like logs.
  • /bin and /usr/bin – system and user executables.
  • /etc – Linux configuration files.

File permissions and ownership are critical for security. They allow control over which users can read, write, or execute files and ensure efficient data management across various environments.

Linux File System Types

Linux supports a variety of file system types, each suitable for different use cases, ranging from general-purpose desktop environments to large-scale enterprise storage solutions. Using the appropriate file system optimizes performance, reliability, and data management.

The table below outlines key Linux file systems, their main features, advantages, and common applications:

File SystemUse CaseFeaturesMain Pros/Cons
ext4Default on most Linux distributions. Suitable for general-purpose systems, including desktops and servers.Journaling for crash recovery.
Support for volumes up to 1 EiB and files up to 16 TiB.
Fast mount times and delayed allocation for better performance.
Mature and stable with extensive community support.
Lacks advanced features like snapshots.
XFSIdeal for high-performance environments that handle large files, such as media servers or databases.High throughput with large files and scalable to massive storage.
Good support for parallel I/O operations.
Online defragmentation and resizing.
Poor performance with many small files.
Complex to tune and manage effectively.
BtrfsUsed for advanced use cases that require snapshots, subvolumes, or integrated volume management; often found in modern servers and storage appliances.Snapshotting, RAID support, self-healing via checksums.
Support for compression and deduplication.
Online resizing and defragmentation.
Less mature than ext4.
Stability issues in certain use cases.
ZFSSuitable for environments that require extreme data integrity, such as enterprise servers, backups, and NAS devices.Combines file system and volume management.
RAID-Z, data deduplication, and end-to-end data integrity verification.
Supports pools with immense storage capacities.
Requires substantial memory for optimal performance (8 GB+).
Licensing restrictions (CDDL vs. GPL).
exFAT & NTFS (via ntfs-3g)Typical choice for dual-boot setups or external drives shared between Linux and Windows.Read/write support for NTFS and exFAT partitions on Linux.
exFAT is optimized for flash drives and SD cards.
NTFS supports advanced Windows-specific features.
ntfs-3g performance can be slower compared to native NTFS on Windows.exFAT does not support journaling, which limits data recovery options.

Linux File System Structure

The Linux file system structure is hierarchical, starting from the root directory (/) and branching into subdirectories like /bin for binaries, /etc for configuration files, and /home for user data. Unlike Windows, Linux uses a unified directory structure, with additional storage devices mounted within this hierarchy.

The system manages files and directories through inodes, which store metadata like permissions and ownership. Additionally, Linux stores everything as a file, including directories, printers, partitions, kernel data, etc. The file permissions model thus ensures secure and efficient management of files across different users and environments, from desktops to large-scale servers.

Linux File System Features

Linux file systems offer a range of features that optimize performance, security, and data integrity. Below are the key features that define the functionality and reliability of Linux file systems:

Journaling

Modern Linux file systems such as ext4 and XFS support journaling, which helps protect against data corruption in case of a system crash or power failure. Journaling records modifications and ensures data consistency and quick recovery after sudden shutdowns.

The following graph shows some key features of the ext4 file system, one of the most widespread file system types in Linux:

Permissions and Security

Linux uses a robust permissions model to control file access. Each file has an ownergroup, and permission settings (read, write, execute) for the owner, group, and others. This system enforces security across multi-user environments and protects sensitive data from unauthorized access.

Mounting

Linux allows users to mount different file systems into a single unified directory structure. Users can mount devices, partitions, and network shares at any point in the directory tree. Such a system provides flexibility in organizing and accessing storage.

Inodes

An inode is a data structure that stores file metadata, including permissions, ownership, and timestamps. Each file and directory is associated with an inode, which helps the system manage file information efficiently.

Snapshots and Backups

Advanced file systems like Btrfs and ZFS support snapshots, which create point-in-time file system copies. These snapshots serve as backups, data recovery, and version control without affecting system performance.

Scalability

File systems like XFS and ZFS easily handle large volumes and files, making them suitable for environments with massive storage needs. They support high scalability, ensuring performance remains stable as the file system grows.

Compression and Deduplication

Btrfs and ZFS offer built-in compression and deduplication features. They allow more efficient storage space use by reducing redundancy and compressing data on the fly.

Mounting Linux File System

Mounting in Linux refers to making a file system accessible at a specific directory within the system’s directory tree. This process is crucial for managing multiple storage devices, partitions, or network shares. Read the sections below to learn the key concepts and steps involved in mounting file systems on Linux.

Mount Point

A mount point is a directory where the system attaches an additional file system. For example, a separate partition can be mounted at /mnt/data, allowing access to its contents from this directory. Any directory can be used as a mount point, and multiple file systems can be mounted across different locations within the directory tree.

The mount Command

The mount command allows users to mount additional file systems to a certain mount point on the currently accessible file system. The command syntax is:

mount -t [type] [device] [dir]

The command passes the mount instructions to the kernel, which completes the operation. For example:

sudo mount /dev/sdb1 /mnt/media

The command above mounts the /dev/sdb1 file system to the /mnt/media directory.

The /etc/fstab File

Linux uses the /etc/fstab configuration file to mount file systems on boot automatically. The file contains instructions on where to mount which devices, along with information on the file system type and mount behavior. Below is an example entry in the /etc/fstab file:

/dev/sdb1   /mnt/data   ext4   defaults   0  2

The entry above instructs the system to mount the file system at /mnt/data every time the system starts.

Mount Options

Various options are available to control system behavior during file system mounting. These options can be added via the mount command or configured in /etc/fstab. Some common mount options include:

  • ro. Mounts the file system as read-only and prevents write operations.
  • rw. Mounts the file system with read and write permissions (default).
  • noatime. Disables the update of access time on files, improving performance.
  • nosuid. Blocks the execution of setuid and setgid bits to enhance security.
  • nodev. Prevents device file interpretation to improve security on non-root file systems.

Unmounting with umount

Use the umount command to disconnect a file system safely. The command detaches the file system after all pending read/write operations are complete. The syntax is:

sudo umount [device/dir]

Unmounting is necessary before removing a storage device or making system changes to avoid data corruption.

Linux File System Limitations

Despite the robust and flexible nature of Linux file systems, each has certain limitations. These limitations vary depending on the file system type and use case. Below are some common limitations across various Linux file systems.

Volume and File Size Limits

Each file system has its maximum volume and file size limits. For example, ext4 is sufficient for most users when it comes to file and volume size limits but may not be enough for environments handling extremely large datasets.

XFS and ZFS offer higher limits, but even these systems have practical constraints on scalability in certain scenarios.

The table below provides a comparison of sizing limits for common file systems:

File SystemMaximum Volume SizeMaximum File Size
ext41 EiB16 TiB
XFS8 EiB8 EiB
Btrfs16 EiB16 TiB
ZFS256 EiB16 TiB
exFAT128 EiB16 TiB
NTFS256 EiB16 TiB

Fragmentation

File system fragmentation occurs over time as users create, delete, or modify files, which leads to non-contiguous storage. While ext4 handles fragmentation well under normal use, file systems like XFS may require occasional defragmentation, especially when dealing with large files. Some file systems, like Btrfs, have built-in tools to manage fragmentation more efficiently.

Performance with Small Files

Some file systems, particularly XFS, are optimized for handling large files and may struggle with performance when managing many small files. In environments where frequent access to small files is common, file systems like ext4 or Btrfs may offer better performance.

Data Corruption and Recovery

While file systems like Btrfs and ZFS offer advanced features like snapshots and error detection, others like ext4 lack such mechanisms. In case of data corruption, recovery options may be limited, relying on backups or third-party tools. Additionally, exFAT lacks journaling, increasing the risk of corruption in case of an unexpected shutdown.

Limited Support for Certain Features

Not all Linux file systems support advanced features such as compressiondeduplication, or native encryption. For example, ext4 does not natively support these features, while Btrfs and ZFS do. Choosing a file system without these capabilities may require external tools or alternative methods to achieve similar functionality.

Compatibility and Licensing

Some file systems, like ZFS, face licensing conflicts (CDDL vs. GPL), which limits their integration into certain Linux distributions by default. Users may need to install ZFS manually, and compatibility issues could arise when using ZFS on Linux systems.

Which Linux File System Should I Use?

Choosing the right Linux file system depends on your specific needs, such as performance, scalability, reliability, and the intended use case. Consider the following points when choosing a file system:

  • ext4. The default and most widely used file system for Linux. ext4 is a safe choice for general-purpose use, including desktops and servers. It offers a balance of performance, stability, and ease of use, making it ideal for most users who do not need advanced features like snapshots or RAID.
  • XFS. If you need to handle large files and high I/O workloads, such as for media servers, large-scale databases, or scientific computing, XFS is a good choice. It is highly scalable and offers excellent performance for workloads involving big files but may not perform as well with many small files.
  • Btrfs. For users who require advanced features like snapshots, compression, and subvolumes, Btrfs is a suitable option. It is ideal for modern servers and storage appliances where flexibility and data integrity are priorities. However, it may not be as mature or stable as ext4 in some environments.
  • ZFS. ZFS is the best choice if your priority is data integrity and reliability, especially in enterprise environments or for backups. It provides features like snapshots, RAID support, and error correction, making it suitable for mission-critical systems, but it requires more memory and may have licensing conflicts with certain Linux distributions.
  • exFAT or NTFS. For systems that need to interact with Windows, such as dual-boot setups or external drives, exFAT (for flash drives) and NTFS (for hard drives) are recommended. They offer cross-platform compatibility but may lack some advanced features in native Linux file systems.

Ultimately, the best file system depends on the type of data, expected workloads, and your specific environment. For general use, ext4 is a reliable default. Consider file systems like XFS, Btrfs, or ZFS for more specialized needs.

Let’s dive in deeper to understand what all the above directories are:

/

  • The base of the Linux directory (Forward Slash)

  • The starting point of the FSH

  • In Linux, everything is treated as files

/bin

  • Contains executable files that are used to run various system commands & utilities

  • These executables can be executed by regular users

  • Example: cp, mv, cat, ls, etc

/boot

  • Stores files related to the booting process of the Linux system

  • Example: Boot loader config files, kernel images, etc

/dev

  • Contains device files

  • Used to interact with various devices in system such as disks, partitions, printers, and other hardware devices

/etc

  • Stores configuration files for system wide settings, applications, services, and daemons

  • Example: /etc/passwd, /etc/hosts, /etc/fstab and etc

/home

  • Stores home directories of all regular users of the system

  • Example: /home/<username>

/lib

  • Used to store important shared libraries

/media

  • Used as a mount point for mounting removable media like CDs, DVDs, USB drives and other external devices

/mnt

  • Mnt stands for mount point

  • Mount point for temporarily mounting file systems, devices, or network shares

/opt

  • Directory used for installing optional or add-on software packages which are part of the base system

  • Example: third party softwares

/proc

  • Proc stands for process

  • Virtual file system which is used to interact with the kernel to get the system process information, system resources, hardware config and etc in real time

  • Example: /proc/cpuinfo, /proc/meminfo

/root

  • Home directory for the root user where root users config files, personal files and settings are stored

/sbin

  • Stores system executable or binaries

  • These binaries are reserved to be executed by system admins

/tmp

  • Tmp stands for temporary

  • Used to store temporary files that are created and used by various programs and processes by the system

  • Tmp folder is cleaned after every reboot

/usr

  • Usr stands for Unix System Resources

  • Used to store user related files, libraries, etc

  • Example: /usr/bin, /usr/sbin, /usr/local and etc

/var

  • Var stands for variables files

  • Used to store files that are expected to grow/shrink over time

  • Example: Log files, spool files, temporary files