Code-Memo

Linux File System Architecture

The Linux File System Hierarchy

The Linux file system is structured in a hierarchical format, starting from the root directory / and branching into subdirectories. Each directory has a specific purpose, and understanding these can help you navigate and manage a Linux system more effectively.

Root Directory /

The root directory is the top-level directory in the Linux file system hierarchy. All other directories and files are nested within this root directory.

Key Directories Under /

/bin - Essential User Binaries

Contains essential command binaries (executables) needed for single-user mode and for all users. These commands are required for the system to boot and function correctly.

/sbin - System Binaries

Holds essential system binaries that are typically used by the system administrator. These binaries are essential for system maintenance and repair.

/etc - Configuration Files

Contains all the system-wide configuration files and shell scripts that are used to boot and initialize system settings.

/home - User Home Directories

Holds the home directories of all users. Each user has a subdirectory under /home where their personal files, configurations, and settings are stored.

/root - Root User’s Home Directory

The home directory of the root user (the superuser). It is separate from the /home directory to ensure the root user’s files are isolated for security and system integrity.

/lib - Essential Shared Libraries

Contains essential shared libraries and kernel modules required for the binaries in /bin and /sbin.

/usr - User Binaries and Read-Only Data

Stands for “Unix System Resources” and contains user utilities and applications. This directory is further subdivided to organize its contents.

/var - Variable Files

Contains variable data files. This includes files that are expected to grow over time, such as logs, databases, cache, and spool files.

/tmp - Temporary Files

Holds temporary files created by system and user processes. Files in /tmp are often deleted on system reboot.

/dev - Device Files

Contains device files that represent hardware devices. These are special files that allow software to interact with hardware devices like disks, terminals, and printers.

/mnt - Mount Directory

A generic mount point under which temporary file systems can be mounted. Often used for mounting external storage devices like USB drives.

/media - Removable Media

Contains subdirectories for mounting removable media such as USB drives, CD-ROMs, and DVDs.

/opt - Optional Packages

Used for installing additional software packages that are not part of the default Linux distribution. Often contains commercial software.

/srv - Service Data

Holds data for services provided by the system, such as web and FTP servers.

/proc - Process Information

A virtual file system that provides a mechanism to access process information and kernel information. It contains a hierarchy of special files representing the current state of the kernel.

/sys - System Information

Another virtual file system similar to /proc that exposes information about the system and allows interaction with the kernel.

/run - Runtime Data

Contains transient runtime data since the last boot. It is used for storing data that should not persist across reboots.

/boot - Boot Loader Files

Contains files related to the boot loader and kernel. These are essential for the system to boot.

/lost+found - Recovered Files

A directory used by the fsck (file system check) utility for recovering lost files. It exists on every partition with a file system.

How It All Works Together

The Linux file system hierarchy is designed to keep the system organized and efficient. Each directory has a specific role, ensuring that files are systematically categorized based on their function and usage. This structure allows users and system administrators to easily locate and manage files and ensures that the operating system operates smoothly.