An In-Depth Overview of the Linux File System Hierarchy

Understanding the Linux File System Hierarchy is important for Linux users, particularly system administrators and developers.

Grant Knoetze, Contributor

July 21, 2023

9 Min Read
business person looking at the scheme of hierarchy
Alamy

Linux operating systems use a hierarchical file system, which means that it is organized from top to bottom (or above and below).

The starting point of the file system is called the root directory, and all other directories stem from it. Directories above others are called parents or parent directories, while directories below are called children. Children of children are called grandchildren.

In this article, I will provide a detailed overview of the Linux File System Hierarchy, including the importance of directories within the root directory.

Linux File System Hierarchy Structure

The Linux File System Hierarchy Structure is governed by the Filesystem Hierarchy Standard, a set of guidelines that determines the structure and contents of directories in Unix-type operating systems, including Linux. These standards are maintained by the Linux Foundation.

The File System Hierarchy starts at the root directory of the file system, from which all other directories and their contents branch out. The file system logically organizes files and folders, with each directory serving a specific purpose. I will explain the significance of various directories below.

Why Is It Important To Understand the File System Hierarchy?

Having a clear understanding of the Linux File System Hierarchy brings numerous benefits to users. Most notably, it simplifies navigation through the file system and makes it easy to locate files and folders. Moreover, it provides insights into the relationships between different files and folders.

This knowledge makes it easier to perform file management tasks like copying, deleting, moving, and renaming files and folders.

Understanding the Linux File System Hierarchy is particularly crucial for system administrators and developers.

Common Directories in the Linux File System Hierarchy

In the Linux File System Hierarchy, all directories are located under the rootdirectory. It’s important to note that the “root” folder found in the root directory is not the same as the root directory itself. Instead, it serves as the home directory for the root user.

Root directory

The root directory, denoted by a forward slash (/), marks the starting point of the Linux File System. It is positioned at the topmost level, serving as the foundation for the entire file system. All other directories are classified as children or grandchildren of the rootdirectory.

The Linux root directory houses the directories that are necessary for the system to function properly. These directories contain things like configuration files and logs.

When the ls / command is executed in the terminal, the content of the root directory is displayed, encompassing all directories and files (see Figure 1).

shows the output of the ls / command and all the directories contained in the root directory

image001_8

Figure 1. All the directories contained in the root directory.

/home directory

The /home directory serves as a private directory for each user, containing individual user home directories such as Documents, Downloads, Desktop, Pictures, etc. Each registered user on the system has their own subdirectory within /home. This directory ensures user privacy and isolates user data from system-wide files. Figure 2 shows the contents of the /home/grant directory as an example.

shows the contents of the /home/grant directory

image002_5

Figure 2. The contents of the /home/grant directory.

/bin directory

The /bin directory holds essential binary files (executables) that are essential for the proper functioning of the system. For example, basic Linux commands like cp, ls, and echo exist as binary files within the /bin directory. These files are accessible to all users.

shows the contents of the /bin directory

image003_7

Figure 3. The contents of the /bin directory.

/sbin directory

The /sbin directory is dedicated to holding executable binary files used by the system administrator. The binaries play a critical role in performing system administration tasks, such as system maintenance, networking, and system recovery.

shows the contents of the /sbin directory

image004_3

Figure 4. The contents of the /sbin directory.

/etc directory

The /etc directory serves as a repository for host-specific system-wide configuration files required by all programs on the system. These configuration files control various aspects of the Linux system, including network configuration, authentication, services, and hardware settings.

Important files housed in the /etc directory include the following:

/dev directory

In Linux, everything is treated as a file. The /dev directory houses all device files, which represent both physical and virtual devices connected to the system. Device files enable interaction with hardware devices.

Within the /dev directory, you can find various devices, including disks and disk drives, which are known as block devices in Linux. The hard disks (mass storage devices) connected to the system are represented by device files such as /dev/sda (1,2,3, etc.), while USB devices are denoted by device files like /dev/usb (1,2,3, etc.).

shows the contents of the /dev directory

image005_3

Figure 5. The contents of the /dev directory.

/var directory

The /var directory contains variablefiles that change during the operation of the system. An important subdirectory within /var is /var/log, which houses all system log files, including syslog and kern.log. These log files capture kernel events, system events, as well as security events like authentication and logins.

Other subdirectories within the /var directory include /var/spool for storing data that is awaiting processing by programs or users, such as print jobs queues and mail queues; /var/tmp for holding temporary files that are typically not preserved during system reboots; and /var/cache, which contains cached data from applications.

shows the contents of the /var directory.

image006_1

Figure 6. The contents of the /var directory.

/usr directory

The /usr directory is designated for storing all user-related programs and files. The contents within the /usr directory are usually read-only.

Important directories found in the /usr directory include the following:

 

/tmp directory

The /tmp directory contains temporary files generated by the various programs running on the system. These files are typically volatile and don’t survive system reboots.

By using the /tmp directory, programs can share temporary data without encumbering other directories, thus promoting system stability.

/lib directory

The /lib directory contains kernel modules and shared library images. Shared libraries, including the C programming code library, are essential in booting the file system and executing commands within the root file system.

Shared libraries are identified by their file extension *.so. The Windows equivalent would be a Dynamic Link Library (.DLL). These libraries are vital for the normal functioning of the system.

Final Thoughts

The Linux File System is organized logically into a hierarchical structure, which aims to ensure user-friendly and secure usage of the system. The organization provides both system-level protection and individual user privacy.

Traversing and interacting with the file system can be done through both the Graphical User Interface and the command-line terminal, offering flexibility to users. Linux offers many powerful commands and tools to facilitate file system management.

Once you understand the Linux File System Hierarchy, you are a step closer to mastering Linux and becoming a true power user.

Frequently Asked Questions (FAQ)

Q: What is the default directory structure of the Linux File System?

The default structure of the Linux File System is a hierarchical structure that begins with the rootdirectory. All other directories stem from the rootdirectory.

Q: What is an inode and how is it used in the Linux File System?

An inode is an index node. It serves as a unique identifier for a specific piece of metadata on a given filesystem. Each piece of metadata describes what we think of as a file.

Q: How do I manage disk space in the Linux File System?

You can manage disk space using the Graphical User Interface (GUI). Disk space management can be done using a file manager, but you can also use the du (disk usage), and df (disk free)commands in the terminal.

Read this article to learn more about managing disk space: How To Check Linux Disk Space Usage: Classic Sysadmin Tips and Commands

Q: How is data organized in the Linux File System?

Linux uses devicesto receive, send, and store data. Typically, devices correspond to physical hardware components like hard disks, USB sticks, or input/output devices such as a keyboard. However, some devices may not have a hardware component, and in such cases, the kernel provides pseudodevices that you can access as if they were physical devices.

When formatting a partition on a disk, the operating system writes the filesystem, as we have previously discussed, so that you can efficiently organize data within the logical filesystem hierarchy provided by Linux.

Q: What is the difference between the root directory and the home directory in Linux?

The root directory is the topmost level of the Linux File System, and everything, including the home directory, falls under the root directory. The home directory contains the data for a particular user. Every user registered on the system will have their own named directory under the home directory.

Q: How do you create and delete files and directories in the Linux File System?

The creation and deletion of files and folders are possible through both the GUI and the command-line terminal. The GUI provides an intuitive approach where you can simply right-click anywhere and create a new folder.

Alternatively, in the terminal, you can use the mkdir command to create a new directory. Similarly, to create a new file, you can use the touch command.

Here are links to additional resources to help you on your way.

Linux documentation

ITPro Today Linux resources

About the Author(s)

Grant Knoetze

Contributor

Grant Knoetze is a cybersecurity analyst with a special interest in DFIR, programming languages, incident response, red-teaming, and malware analysis. His full-time job includes teaching and instructing in various topics from basic Linux all the way through to malware incident response, and other advanced topics. He is also a speaker at various conferences worldwide.

www.grantknoetze.com

https://github.com/Grant-Knoetze

https://www.linkedin.com/in/grant-knoetze-563b0b1b6/

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like