πŸ“‚ Linux Filesystem Hierarchy β€” Final Comprehensive Summary


πŸ“š Overview

The Linux filesystem is structured as a single inverted tree, starting at the root directory /. Everything (files, devices, sockets, processes) is represented as a file under /.


πŸ”‘ Root Directory /

The top-level directory containing all system files, user files, devices, and mounts.


πŸ“ Key Directories Under /

1. /bin

  • Essential user binaries (commands) needed for booting and single-user mode.
  • Examples: ls, cp, mv, cat, grep, bash.

2. /sbin

  • Essential system binaries for administration, mainly used by root.
  • Examples: init, fsck, ifconfig, reboot.

3. /boot

  • Files needed for booting the system.
  • Kernel (vmlinuz), initramfs (initrd.img), GRUB files.

4. /dev

  • Device files (special files that interface with hardware/peripherals).
  • Examples:

    • /dev/sda β†’ first SATA disk
    • /dev/null β†’ null device
    • /dev/tty β†’ terminal devices

5. /etc

  • System-wide configuration files.
  • Examples:

    • /etc/passwd β†’ user accounts
    • /etc/fstab β†’ filesystem mount table
    • /etc/hosts β†’ hostname mappings

6. /home

  • User home directories.
  • Example: /home/alice, /home/bob

7. /lib, /lib64

  • Essential shared libraries for programs in /bin and /sbin.
  • Examples:

    • /lib/libc.so β†’ C library
    • /lib/modules β†’ kernel modules

8. /media

  • Mount point for removable media.
  • Examples: /media/usb, /media/cdrom

9. /mnt

  • Generic temporary mount point (often used for manual mounts).
  • Example: /mnt/data

10. /opt

  • Optional or third-party software packages.
  • Example: /opt/google/chrome/

11. /proc

  • Virtual filesystem providing process and kernel info.
  • Examples:

    • /proc/cpuinfo
    • /proc/meminfo
    • /proc/[PID]/

12. /root

  • Home directory of the root user (not / itself).

13. /run

  • Volatile runtime data (replaces /var/run in modern systems).
  • Example: process IDs, sockets.

14. /srv

  • Site-specific service data (e.g., web/ftp server files).
  • Example: /srv/www/

15. /sys

  • Virtual filesystem exposing kernel/device info.
  • Example: /sys/class/net/

16. /tmp

  • Temporary files (writable by anyone, usually cleared on reboot).
  • Example: session files, sockets.

17. /usr

  • Secondary hierarchy for user applications and read-only data.
  • Often very large.

    • /usr/bin β†’ non-essential user binaries
    • /usr/sbin β†’ non-essential system binaries
    • /usr/lib β†’ libraries
    • /usr/include β†’ header files
    • /usr/share β†’ architecture-independent data (man pages, docs, icons)
    • /usr/local β†’ locally installed software

18. /var

  • Variable files (expected to grow).

    • /var/log β†’ log files
    • /var/spool β†’ queued tasks (print, mail)
    • /var/tmp β†’ temp files that persist across reboots
    • /var/cache β†’ cached data

πŸ—‚ Special Notes

  • Everything is a file: devices, processes, sockets.
  • Hard vs Soft links: Multiple references to files.
  • Mount points: Additional filesystems mounted under /.
  • Virtual filesystems: /proc and /sys don’t hold real files, but kernel-generated info.

βœ… Mnemonic Tip:

  • bin/sbin β†’ binaries
  • etc β†’ configuration
  • var β†’ variable data
  • usr β†’ user apps
  • lib β†’ libraries
  • dev β†’ devices
  • proc/sys β†’ system + kernel info

🌳 Full Directory Tree with Annotations

/                               # root of the entire filesystem tree
β”œβ”€ bin/                         # essential user commands (ls, cp, mv, cat, bash)
β”œβ”€ sbin/                        # essential system binaries for root (init, reboot, fsck)
β”œβ”€ boot/                        # boot loader + kernel
β”‚   β”œβ”€ vmlinuz                  # Linux kernel
β”‚   β”œβ”€ initrd.img               # initial RAM disk
β”‚   └─ grub/                    # GRUB bootloader files
β”œβ”€ dev/                         # device files (interface to hardware/peripherals)
β”‚   β”œβ”€ sda                      # first hard disk
β”‚   β”œβ”€ null                     # discard output
β”‚   β”œβ”€ tty                      # terminals
β”‚   └─ random                   # random number generator
β”œβ”€ etc/                         # system-wide configuration files
β”‚   β”œβ”€ passwd                   # user accounts
β”‚   β”œβ”€ shadow                   # secure user passwords
β”‚   β”œβ”€ fstab                    # filesystem mount table
β”‚   └─ hosts                    # static hostname mappings
β”œβ”€ home/                        # user home directories
β”‚   β”œβ”€ alice/                   # home dir for user "alice"
β”‚   └─ bob/                     # home dir for user "bob"
β”œβ”€ lib/                         # essential shared libraries for /bin and /sbin
β”œβ”€ lib64/                       # 64-bit libraries (on 64-bit systems)
β”œβ”€ media/                       # mount points for removable media (USB, CD-ROM)
β”œβ”€ mnt/                         # generic temporary mount point (manual use)
β”œβ”€ opt/                         # optional / third-party software
β”œβ”€ proc/                        # virtual filesystem with process & kernel info
β”‚   β”œβ”€ cpuinfo                  # CPU details
β”‚   β”œβ”€ meminfo                  # memory details
β”‚   └─ [PID]/                   # info for each running process
β”œβ”€ root/                        # root user’s home directory
β”œβ”€ run/                         # volatile runtime data (PID files, sockets) β€” cleared on reboot
β”œβ”€ srv/                         # service-specific data (web, ftp, etc.)
β”œβ”€ sys/                         # virtual filesystem exposing kernel & device info
β”œβ”€ tmp/                         # temporary files (world-writable, cleared on reboot)
β”œβ”€ usr/                         # user applications and read-only data (very large)
β”‚   β”œβ”€ bin/                     # non-essential user commands (awk, gcc, python)
β”‚   β”œβ”€ sbin/                    # non-essential system binaries (httpd, named)
β”‚   β”œβ”€ lib/                     # libraries for /usr/bin and /usr/sbin
β”‚   β”œβ”€ include/                 # header files (C, C++)
β”‚   β”œβ”€ share/                   # arch-independent data (docs, man pages, icons)
β”‚   └─ local/                   # locally installed software (safe from package manager)
└─ var/                         # variable data files (changes frequently)
    β”œβ”€ log/                     # log files (syslog, dmesg, auth.log)
    β”œβ”€ spool/                   # queued tasks (mail, print jobs)
    β”œβ”€ tmp/                     # temporary files that persist across reboot
    └─ cache/                   # application cache data

πŸ”‘ Key Principles

  • Everything is a file: devices, sockets, processes, directories.
  • Essential binaries β†’ /bin, /sbin.
  • Configuration β†’ /etc.
  • User data β†’ /home.
  • Variable data β†’ /var.
  • Kernel + process info β†’ /proc, /sys.
  • Boot files β†’ /boot.
  • Temporary storage β†’ /tmp, /var/tmp.
  • 3rd party software β†’ /opt, /usr/local.

βœ… This summary gives you:

  • A tree-structured overview (easy to visualize).
  • Detailed annotations (purpose + examples).
  • A unified cheat sheet for study or quick reference.