Hacker Wiki

Hacking The Planet since 2004

User Tools

Site Tools


understanding_the_linux_file_system

This is an old revision of the document!


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:

  • – The root directory of the entire file system * /bin – Essential user binaries (e.g., `ls`, `cp`, `mv`) * /sbin – Essential system binaries (e.g., `fsck`, `reboot`) * /etc – Configuration files * /home – User home directories * /var – Variable data (e.g., logs, spool files) * /usr – User applications and utilities * /tmp – Temporary files * /boot – Bootloader and kernel files * /dev – Device files * /proc – Virtual filesystem for system and process information * /sys – Interface to the kernel * /mnt and /media – Mount points for external devices ===== 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: * `-` Regular file (e.g., documents, scripts) * `d` Directory * `l` Symbolic link * `c` Character device file * `b` Block device file * `s` Socket * `p` Named pipe (FIFO) 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: * File type * Permissions * Owner and group * Timestamps (created, modified, accessed) * Number of hard links * Pointers to data blocks 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: <code bash> sudo mount /dev/sdb1 /mnt/external </code> Unmounting: <code bash> sudo umount /mnt/external </code> 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: * `/dev/sda1` → `/boot` * `/dev/sda2` → `/` * `/dev/sda3` → `/home` 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: * Owner * Group * Others Each can have: * Read ® * Write (w) * Execute (x) Example permission string: <code> -rwxr-xr– </code> Means: * Owner: read, write, execute * Group: read, execute * Others: read only Management commands: * `chmod` – change permissions * `chown` – change owner * `chgrp` – change group ===== Symbolic and Hard Links ===== ==== Hard Links ==== Hard links point to the same inode. Deleting one does not remove the file as long as other links exist. <code> ln file1 file2 </code> ==== Symbolic Links ==== Symlinks point to a file path. <code> ln -s /path/to/original symlink </code> Can cross file systems. Often used for shortcuts or config management. ===== Special Directories and Files ===== ==== /dev ==== Contains device files. Examples: * `/dev/sda` – hard disk * `/dev/null` – discard input * `/dev/tty` – terminal devices ==== /proc ==== Virtual FS with system and process info. Examples: * `/proc/cpuinfo` * `/proc/meminfo` ==== /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. * /proc – Process and system info (not stored on disk) * /sys – Kernel interaction * /run** – Runtime state files (like PID files)

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

Disk Usage and File System Tools

Viewing Disk Usage

  • `df -h` – disk space on mounted file systems
  • `du -sh *` – usage of files/folders

Checking and Repairing

  • `fsck` – filesystem consistency check
  • `tune2fs` – tweak ext options

Mounting and Unmounting

  • `mount`
  • `umount`

Partition Tools

  • `fdisk` – legacy CLI partition manager
  • `parted` – GPT and modern disk support
  • `lsblk` – block device info
  • `blkid` – UUID and label lookup

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.

Would you like a downloadable `.txt` version for direct upload into your DokuWiki system?

understanding_the_linux_file_system.1745215691.txt.gz · Last modified: 2025/04/21 06:08 by hacktheplanet