Understanding the Linux File System

The Linux file system is one of the most powerful and defining features of the Linux operating system. Unlike some operating systems that may abstract or simplify the underlying file structure, Linux offers a transparent, flexible, and unified file system architecture. Understanding how it works is essential for both everyday users and system administrators.

Table of Contents

Introduction to File Systems

A file system (FS) is a method and data structure that an operating system uses to control how data is stored and retrieved. Without a file system, stored data would be one large body of data with no way to tell where one piece of information stops and the next begins.

In Linux, the file system is not just limited to physical hard drives. It’s a unified, hierarchical structure where everything is treated as a file: documents, directories, devices, and even processes.

Linux Filesystem Hierarchy Standard (FHS)

Linux adheres to the Filesystem Hierarchy Standard (FHS), which defines the directory structure and content in Unix-like systems. At the core is the root directory, represented as a single forward slash `/`.

Here’s a high-level overview of essential top-level directories:

Linux File Types

Linux supports several file types, all of which can be listed using `ls -l` with a type-indicating character at the beginning:

Each plays a unique role in the system's function, especially device and special files under `/dev`.

Inodes and Data Blocks

Every file in Linux is represented by an inode (index node). An inode contains metadata about the file:

Inodes do not store file names. The directory structure maps filenames to inode numbers. This separation allows for powerful features like hard links.

File System Mounting

In Linux, everything exists under a single directory tree rooted at `/`. When a filesystem is mounted, it is attached to an existing directory (called a mount point).

Example mount command:

sudo mount /dev/sdb1 /mnt/external

Unmounting:

sudo umount /mnt/external

Persistent mounts are defined in `/etc/fstab`.

Partitions and Mount Points

A storage device is often divided into partitions, each formatted with a file system type like `ext4` or `XFS`.

Examples:

This partitioning allows improved isolation and easier backups or reinstalls.

Common Linux File Systems

ext4

The most common Linux file system. Offers journaling, large volume support, and backward compatibility with ext3.

XFS

High-performance journaling file system, best for large files and high-throughput environments.

Btrfs

Next-gen file system with snapshots, compression, RAID support.

FAT32/exFAT/NTFS

Windows-compatible file systems. Used for USB drives or dual-boot setups.

Swap

Used for virtual memory. Not a traditional file system.

Permissions and Ownership

Linux uses a permission model for each file and directory:

Each can have:

Example permission string:

-rwxr-xr--

Means:

Management commands:

Hard links point to the same inode. Deleting one does not remove the file as long as other links exist.

ln file1 file2

Symlinks point to a file path.

ln -s /path/to/original symlink

Can cross file systems. Often used for shortcuts or config management.

Special Directories and Files

/dev

Contains device files. Examples:

/proc

Virtual FS with system and process info.

Examples:

/sys

Interface to kernel modules and devices.

Virtual File Systems: /proc and /sys

Virtual file systems provide real-time, in-memory views of system status.

You can read/write these with tools like `cat`, `echo`, or `grep`.

Disk Usage and File System Tools

Viewing Disk Usage

Checking and Repairing

Mounting and Unmounting

Partition Tools

Conclusion

The Linux file system is vast and elegant, adhering to a logical hierarchy while offering advanced features like virtual file systems, symbolic links, and permission-based access control. Everything in Linux—from hardware to processes—is accessed through this unified system.

Whether you’re managing devices, setting up partitions, or browsing log files in `/var`, understanding the Linux file system is fundamental to mastering the OS.