Skip to main content
Linux

A Quick Introduction To The Default Linux File System Hierarchy (FSH)

Christian Schou

Have you ever wondered what the default file system hierarchy looks like in a standard Linux installation and why it's great? Then you are in the right place.

The File System Hierarchy (FSH) in Linux is a standard in the Linux ecosystem that all the other Linux distributions build on top of. This makes it much easier for developers of other distributions to develop, package, and maintain their distro.

What does the File System Hierarchy look like?

Let's take a look at what the file system looks like if we split it out in a graphic view.

In the image above you can see that the file system consists of 18 folders making up the default file system in Linux. Curious about what each of them contains? Let's break them down one by one and see what they are used for.

Root (top level of the hierarchy)

The root directory serves as the starting point for the entire file system hierarchy in Linux. It contains essential system files and directories necessary for the functioning of the operating system. Here are a few things to note about the root directory.

  • All other directories and files are organized under the root directory.
  • The root directory is denoted by a forward slash /.
  • Users with administrative privileges, often referred to as the root user have full control over the entire file system starting from this root directory. (very powerful)
  • It is the base directory from which all other directories and subdirectories stem, forming the hierarchical structure of the Linux filesystem.

Binaries /bin

The /bin directory, short for binary, houses fundamental executable files that are crucial for the system's basic functionality. These binaries include essential commands and utilities that are required for system maintenance and recovery, such as basic shell commands like ls (list), cp (copy), and mv (move).

As a key component of the root file system, /bin ensures that fundamental tools are readily available to all users, regardless of their specific roles. You can think of it as the toolbox containing the everyday tools necessary for running and managing the system effectively.

Boot Loader Files /boot

The /boot directory is where the essential components for booting the operating system are stored. It contains critical files like the Linux kernel, which is the core of the operating system responsible for managing system resources and facilitating communication between hardware and software.

Bootloader configuration files, such as GRUB or LILO, lives here, guiding the system on how to initiate and load the operating system during startup. The files in /boot are pivotal for the initial stages of the boot process, ensuring a smooth and successful start-up of the Linux operating system.

This directory acts as the launchpad for your system when you turn it on, holding the key elements needed to kickstart the entire operating system.

Device Files /dev

The /dev directory, standing for device, is a virtual filesystem that serves as a communication bridge between software and hardware. It contains special files, known as device files, representing both physical and virtual devices connected to the system. These files enable programs to interact with hardware components seamlessly.

Each device file in /dev is a portal through which applications and the operating system communicate with devices like hard drives, printers, USB ports, and more. For example, /dev/sda may represent the first hard disk, and /dev/ttyUSB0 could correspond to a USB serial port.

You can think of /dev as the backstage pass granting software access to the diverse array of devices connected to your system (hardware), facilitating a smooth flow of data and commands between the software layer and the underlying hardware.

System Configuration Files /etc

The /etc directory, often pronounced as "et cetera" or simply "etcetera," is the central hub for system-wide configuration files and scripts in Linux. It stores crucial configuration files that control the behavior of various applications, services, and the overall operating system.

Administrators use /etc to customize system settings, manage user access, and define parameters for installed software.

💡
Examples of configuration files found here include /etc/passwd for user account information, /etc/network/interfaces for network configuration, and /etc/apt/sources.list for package management settings.

In essence, /etc acts as the nerve center for system configuration, offering a centralized location where administrators can tailor the system to meet specific requirements and preferences.

Home Directories /home

The /home directory is the designated space where personal user directories are housed in the Linux file system. Each user with an account on the system typically has a dedicated subdirectory within /home where they can store personal files, documents, configurations, and other user-specific data.

For instance, if a user named John has an account on the system, his personal space would be located at /home/john.

/home fosters organization and user privacy by segregating individual user data, making it convenient for users to manage their files without interference from other users.

It symbolizes the personalized and private realm for users within the broader Linux environment, emphasizing user-centric organization and accessibility.

Shared Libraries and Kernel Modules /lib

The /lib directory, short for library, contains essential shared libraries that are critical for the functioning of system binaries and other programs during runtime. Shared libraries contain code and resources that multiple programs can use simultaneously, promoting efficiency by reducing redundancy. ✌️

The contents of /lib are dynamic link libraries (*.so files) that provide functions and resources needed by executable programs. These libraries are loaded into memory when programs are executed.

Commonly used shared libraries, such as libc (C library), are stored here, facilitating compatibility and resource sharing among a variety of applications.

You can think of /lib as a shared resource pool where programs gather the necessary tools and functions to operate smoothly, promoting a more efficient and streamlined computing experience.

Removable Media /media

The /media directory is a designated location for mounting removable media in the Linux file system. When external devices like USB drives, CDs, DVDs, or other removable storage media are connected to the system, their contents are typically accessed through subdirectories within /media.

Each mounted device is assigned a unique subdirectory under /media, allowing users to access and interact with the data stored on these external media sources.

/media serves as a temporary connection point, facilitating seamless access to external media while maintaining an organized and consistent file system structure. It's akin to a virtual docking station where external devices briefly dock to integrate with the system, enabling users to utilize and manage external data efficiently.

Mount Point for Temporarily Mounted Filesystems /mnt

The /mnt directory, an abbreviation for mount, is a general-purpose location used by system administrators for temporarily mounting filesystems or devices.

While /media is commonly used for the automatic mounting of removable media, /mnt provides a more manual and flexible approach for mounting various filesystems, network shares, or temporary storage devices.

Administrators may create subdirectories within /mnt to mount and access specific filesystems or devices on demand. Unlike /media, which is often managed automatically by the system, /mnt is a location where users or administrators can explicitly control the mounting and unmounting of filesystems as needed.

It serves as a staging area for connecting external or networked resources to the system, giving administrators the flexibility to manage these connections based on specific requirements.

Optional Add-on Software /opt

The /opt directory, short for optional, is reserved for the installation of optional or add-on software packages that are not part of the default system installation.

It provides a standardized location for third-party software vendors to install their applications, preventing conflicts with system files and ensuring a clean separation between system and optional software. Each application or package installed in /opt typically has its subdirectory structure, making it self-contained and isolated from the rest of the system.

System administrators can manage optional software in /opt without affecting the core system files, promoting modularity and simplifying software installation and removal.

You can think of /opt as a dedicated space for additional software, allowing users to extend and customize their Linux environment with supplementary applications that suit their specific needs.

Process Information /proc

The /proc directory is a virtual filesystem that provides a window into the kernel's view of the system, offering real-time information about running processes and system status.

Unlike traditional directories that store files on disk, /proc exists in memory and dynamically reflects the current state of the system. Users and system utilities can access and manipulate information in /proc to gather details about processes, memory usage, hardware configuration, and more.

Each entry in /proc corresponds to a process or a system parameter, and interacting with these entries allows users to observe and modify various aspects of the operating system.

/proc acts as a portal for monitoring and interacting with the dynamic and evolving aspects of the Linux kernel and the processes running on the system, providing invaluable insights for system analysis and troubleshooting.

🤓
So, in a nutshell, /proc is like a magic window that shows you exactly what's going on inside your computer right now. It's super useful for computer experts to understand and fix things when there's a problem.

Here is an example using cat /proc/cpuinfo in the terminal.

processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 94
model name  : Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
stepping    : 3
microcode   : 0xc6
cpu MHz     : 800.000
cache size  : 6144 KB
...

Root User's Home Directory /root

The /root directory is the home directory for the system's superuser, often referred to as the root user or simply root. Unlike regular users who have their home directories under /home, the root user's home directory is /root.

The root user is the administrator with the highest level of access and control over the entire system. The /root directory serves as the root user's private workspace for storing configuration files and other system-related data.

While regular users have their home directories for personal files, the /root directory is a central location for system administrators to manage crucial system configurations, scripts, and administrative tasks.

Access to /root is restricted to the root user, ensuring that only the highest-level administrator has direct control over these critical system files and settings.

Runtime Data /run

The /run directory is a temporary filesystem that holds volatile runtime data, and it is cleared on each system reboot. It serves as a location for applications and the system to store and access transient files and runtime information during system operation.

/run includes directories for various system components, allowing them to communicate and share data seamlessly. For instance, /run/user may contain runtime information specific to individual users.

If you run ls /run/user in your terminal, you will get something similar to this.

1000  1001  1002
🧐
Here, "1000", "1001", and "1002" are user IDs, and each directory contains runtime information specific to the corresponding user.

This directory is especially useful for applications that need to exchange data or state information quickly without the need for persistent storage.

You can think of /run as a dynamic workspace where the operating system and applications can collaborate in real-time, enhancing performance and responsiveness.

System Binaries /sbin

The /sbin directory, standing for system binary, contains essential system binaries or executables that are primarily used for system administration tasks. These binaries are crucial for the system's basic functionalities, and they are often employed during the boot process or system recovery.

Unlike the binaries in /bin, which are generally available to all users, the executables in /sbin are typically intended for use by the system administrator (root) due to their advanced and system-critical nature.

Examples of commands stored in /sbin include utilities for managing network configurations, disk partitions, and other low-level system tasks.

/sbin ensures that the fundamental tools required for system maintenance and recovery are available in a specific location, accessible primarily to the system administrator for system-level operations.

Service Data /srv

The /srv directory is designed to store data directories for specific services or services provided by the system. It is not predefined by the system but is often used by administrators to keep data associated with services, such as websites, FTP servers, or version control repositories.

/srv provides a way to keep service-related data separate from the system's default directories, promoting organization and easier management of service-specific files.

For example, a web server might have its website files stored in /srv/www or a file server might utilize /srv/fileshare for its data.

While not a standard location for all services, /srv offers a flexible and standardized approach for administrators to structure data associated with various services on a Linux system.

System Files /sys

The /sys directory is a virtual filesystem that exposes information about the kernel, devices, and kernel parameters in a structured manner. It provides a dynamic interface for interacting with and configuring kernel parameters during runtime.

Users and system utilities can access and modify settings in /sys to influence the behavior of the kernel, devices, and other system components.

Entries in /sys often represent kernel parameters, hardware devices, and their configurations. For instance, you might find information about the state of the system's CPU, memory, or connected devices.

/sys acts as a bridge between user space and the Linux kernel, offering a standardized and flexible way to observe and control various aspects of the system's core functionality.

Temporary Files /tmp

The /tmp directory is a designated space for storing temporary files that are needed during system operation. It allows applications and users to create and share temporary files without cluttering up their directories.

The contents of /tmp are typically cleared upon system reboot, ensuring that it remains a transient storage space for short-lived data. Applications often use /tmp to store temporary files, and users might utilize them for tasks like saving files for a brief duration.

It provides a common ground for various processes to exchange temporary data, promoting a standardized approach to handling temporary files in a multi-user environment.

/tmp is an essential part of the Linux filesystem structure, offering a dynamic and shared location for managing temporary data efficiently.

User Programs /usr

The /usr directory is a comprehensive location that houses the majority of user-related programs, utilities, libraries, and documentation on a Linux system. It is a crucial component of the Linux filesystem, containing subdirectories such as /usr/bin for user binaries, /usr/lib for libraries, /usr/share for shared data, and more.

/usr is designed to be sharable and read-only, allowing multiple users on a system to access a common set of applications and resources. User-installed software, additional packages, and application-related files are typically stored in /usr, making it a central hub for extending the functionality of the operating system.

The /usr directory structure follows a modular design, promoting organization and standardization in the storage of user-related files and programs.

You can think of /usr as a vast library that contains a wealth of applications and resources, contributing to the richness and versatility of the Linux environment.

Variable Files /var

The /var directory is designated for variable data—files that are expected to change in size and content during the normal operation of the system.

It includes subdirectories such as /var/log for log files, /var/spool for mail and print spools, and /var/cache for cached data. /var is a dynamic and evolving part of the filesystem, containing data that may change frequently during system operation.

It is often used for files generated by system processes, such as log files recording system events or spool directories storing queued data. Applications, services, and the system itself use /var to store data that is subject to change, ensuring that critical information and stateful data are persistently managed.

You can think of /var as a repository for variable data, providing a structured and organized space for files that reflect the ongoing activities and status of the Linux system.


Summary

I hope you enjoyed this brief tour of the Linux filesystem! Exploring directories like /bin for essential commands, /home for personal user spaces, and /tmp for temporary files reveals the structured backbone of your Linux system.

The /proc directory provides real-time insights, /var dynamically manages changing data, and /usr serves as a treasure trove of user-related resources. Each directory has its role, contributing to the efficiency and functionality of your Linux environment.

Remember, understanding this filesystem makes navigating, customizing, and maintaining your Linux system a breeze. Happy Linux exploring and don't forget to add a comment below if you got any questions! 🎉