Linux File System Hierarchy
1. Overview
β The Linux File System Hierarchy defines how files and directories are structured in Linux.
β Everything in Linux is represented as a file β including devices and processes.
β The top of the hierarchy is the root directory /, from which all other directories branch out.
2. Root Directory /
β The root directory is the starting point of the entire file system.
β Contains all essential system files and directories.
β Every file or directory path begins from /.
3. Key Directories Explained
β /bin
β Contains essential binary executables (programs) needed for basic operations.
β Used by all users and available even in single-user mode.
β Examples: ls, cp, mv, cat, bash.
β /sbin
β Similar to /bin but holds system binaries used for administrative tasks.
β Mostly for the root user.
β Examples: fdisk, ifconfig, reboot, shutdown.
β /boot
β Contains boot-related files needed to start the system.
β Stores the Linux kernel, initramfs, and bootloader (GRUB) configurations.
β Example files: vmlinuz, grub/grub.cfg.
β /dev
β Stands for devices.
β Contains device files representing hardware components like disks, terminals, and USBs.
β Examples: /dev/sda, /dev/tty, /dev/null.
β /etc
β Contains system-wide configuration files and startup scripts.
β Examples: /etc/passwd, /etc/fstab, /etc/hostname, /etc/ssh/sshd_config.
β /home
β Contains user home directories.
β Each user has a separate folder under /home.
β Example: /home/dhanian.
β /lib
β Holds shared libraries and kernel modules needed by programs in /bin and /sbin.
β Similar to dynamic link libraries (DLLs) in Windows.
β Example: /lib/modules, /lib/x86_64-linux-gnu.
β /media
β Used for removable media like USB drives, CDs, or external storage.
β Automatically mounts devices when inserted.
β Example: /media/usb.
β /mnt
β Traditionally used for temporarily mounting filesystems.
β Useful for manual mounts during maintenance.
β Example: mount /dev/sdb1 /mnt.
β /opt
β Stands for optional software.
β Used for installing third-party applications outside the system package manager.
β Example: /opt/google/chrome.
β /proc
β A virtual filesystem providing kernel and process information.
β Does not store real files but dynamic runtime data.
β Examples: /proc/cpuinfo, /proc/meminfo, /proc/<pid>.
β /root
β The home directory of the root user.
β Separate from /home for security reasons.
β Path: /root.
β /run
β Contains runtime data like process IDs and socket files.
β Cleared on every reboot.
β Example: /run/systemd.
β /srv
β Stands for service data.
β Stores files for services like web or FTP servers.
β Example: /srv/www.
β /sys
β Virtual filesystem for kernel and hardware information.
β Used for managing devices and kernel modules.
β Example: /sys/class/net.
β /tmp
β Used for temporary files created by users and applications.
β Automatically cleared on reboot.
β Example: /tmp/install.log.
β /usr
β Stands for Unix System Resources.
β Contains user programs, documentation, and libraries.
β Subdirectories include:
ββ /usr/bin β user commands
ββ /usr/lib β libraries
ββ /usr/share β documentation and data
ββ /usr/local β locally installed software
β /var
β Stands for variable data that changes frequently.
β Stores logs, caches, mail, and spool files.
β Example: /var/log, /var/tmp, /var/spool.
4. Tip
β Linux uses a hierarchical tree structure with / at the top.
β Each directory serves a specific purpose , from configuration to user data.
β Understanding the file system hierarchy is essential for system administration, troubleshooting, and development.
For Mastering Linux, Grab this ebook:
codewithdhanian.gumroad.com/β¦