Linux File System Hierarchy - DevOps Prerequisite 2
Tags: linux, beginners, devops, opensource
Published: 2024-06-02 15:30:20

In this article, we will explore the Linux filesystem hierarchy, detailing its directory structure and how it differs from other operating systems.

**Linux Filesystem**

The Linux OS features a secure, multi-user filesystem with a directory structure designed to balance security and functionality. User-accessible directories are kept separate from those needed by the administrator.

Linux generally adheres to the Filesystem Hierarchy Standard (FHS), established in 1994. This standard outlines the common layout conventions used by most UNIX and UNIX-like systems. It includes a primary (or root) directory with multiple branching sub-directories.

**Root Directory ( / )**

The root directory (/) is the starting point for the entire Linux filesystem hierarchy. It is the top-level directory from which all other filesystems are mounted during system boot. All files and folders branch from the root directory, regardless of where the data is physically stored.

The root directory is owned by the root user (administrator), with permissions tightly controlled to allow only administrators to add, remove, or modify its files and folders.

**Sub-Directories**

Linux conventionally includes several important sub-directories, each with its specific purpose and permissions. Some sub-directories, like /tmp, are accessible to everyone, while others, such as /etc, are restricted to administrators.

Here is a table detailing the purpose of common Linux sub-directories:

| SUB-DIRECTORY | PURPOSE |
| — — — — — — — -| — — — — -|
| /bin | Common binary executables used by all users |
| /boot | Files associated with the boot loader |
| /dev | Attached devices (USB, CD-ROM, mouse, keyboard) |
| /etc | Configuration files |
| /home | Personal directories for each user account |
| /lib | Shared system libraries |
| /media | Directory for mounting removable devices (floppy drive, CD-ROM) |
| /mnt | Directory for mounting filesystems (NFS, SMB) |
| /opt | Optional vendor add-on software |
| /proc | Virtual filesystem for system processes/resources information |
| /root | Home directory for the administrator account |
| /run | Storage for runtime information |
| /sbin | Binary executables used by the administrator |
| /srv | Data for server services |
| /sys | Virtual filesystem for hardware/driver information |
| /tmp | Temporary files purged on reboot |
| /usr | Utilities and read-only user data/programs |
| /var | Variable and log files |

**Linux versus Other Filesystems (macOS and Windows)**

**For Windows User’s Perspective**

Windows and Linux have distinct designs. Unlike Windows’ single-user system, Linux is multi-user. While Windows uses separate data drives (e.g., C:\WINDOWS and D:\DATA), Linux employs a tree-like hierarchy with everything branching from the root. On Windows, program and system files share the same path (C:\Program Files), whereas in Linux, they are separated (e.g., /bin, /boot, /usr/bin).

**For macOS User’s Perspective**

Apple’s macOS, derived from Unix and BSD, has a core file structure similar to Linux. Both have a single primary directory with sub-directories branching from the root (/). Many Linux sub-directory names are found in macOS, though some names differ (e.g., macOS uses /Users instead of /home for user accounts and personal files).

Sub-directory similarities to Linux include:

/bin /etc /dev /usr /sbin /tmp /var

Sub-directories unique to macOS include:

/Applications /Developer /Library /Network /System /Users /Volumes

**Conclusion**

The Linux filesystem, though distinct, shares similarities with other filesystems. This article has highlighted the unique aspects of the Linux filesystem. As you navigate your Linux environment, you will become more familiar with each directory’s purpose.

**Linux Bash Utilities**

Learn about useful Linux Bash utilities!

The Linux shell language, Bash, offers many possibilities for interacting with the OS, including file compression, archiving, and extraction from the command line. It also provides functions for looking up documentation for all commands.

For a foundation in command line basics, consider taking our “Learn the Command Line” course to practice basic navigation and filesystem modifications in Bash.