DEV Community

Sehran Rasool Jan
Sehran Rasool Jan

Posted on

Linux Filesystem Hierarchy

Navigating Linux for the first time can feel overwhelming: where do files go, what do all those directories mean, and how does the system keep it all organized? Whether you're tinkering with your first Linux installation or optimizing a seasoned server, understanding the filesystem layout is key to mastering your workflow.

1. /bin — Essential User Binaries

  • Contains basic command-line tools required by all users.
  • Examples: ls, cat, cp, mv, vim, gzip, curl
  • These commands are available even in single-user mode when no other filesystems are mounted.

2. /sbin — System Binaries

  • Includes commands used for system administration (requires root access).
  • Examples: mount, reboot, fdisk, deluser

3. /lib — Shared Libraries

  • Stores essential shared libraries and kernel modules used by /bin and /sbin.
  • Think of it as the Linux version of Windows .dll files.
  • Example: /lib/x86_64-linux-gnu/libc.so.6

4. /usr — User Programs and Data

  • Contains user-related applications and non-essential binaries.
  • Subdirectories:
    • /usr/bin → User commands
    • /usr/sbin → System binaries
    • /usr/lib → Libraries for /usr/bin and /usr/sbin

5. /usr/local — Locally Installed Software

  • Used for software compiled or installed manually by the user.
  • Keeps them separate from system-managed packages.
  • Example: /usr/local/bin, /usr/local/lib

6. $PATH — Environment Variable

  • Defines directories where the shell looks for executables.
  • View it with: echo $PATH
  • Example: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

7. which — Locate a Command

  • Displays the path of the executable being run.
  • Example: which ls → /bin/ls

8. /etc — Configuration Files

  • Holds system-wide configuration files.
  • Examples: /etc/passwd, /etc/hosts, /etc/fstab, /etc/ssh/sshd_config

9. /home — User Home Directories

  • Each user has their own directory here.
  • Examples: /home/sehran, /home/adnan
  • Shortcut: ~ points to your home directory.

10. /boot — Boot Loader Files

  • Contains files required to boot the Linux kernel.
  • Includes the kernel image, initial RAM disk, and bootloader configurations (like GRUB).
  • Examples: /boot/vmlinuz, /boot/initrd.img, /boot/grub/grub.cfg

11. /dev — Device Files

  • Represents hardware devices as files.
  • Examples:
    • /dev/sda → Hard disk
    • /dev/tty → Terminal
    • /dev/null → Data sink

12. /opt — Optional or Third-Party Software

  • Used for optional or vendor-installed applications.
  • Example: /opt/google/chrome/

13. /var — Variable Data Files

  • Contains data that changes frequently, like logs or cache.
  • Subdirectories:
    • /var/log → System logs
    • /var/cache → Cached data
    • /var/spool → Pending tasks

14. /tmp — Temporary Files

  • Used to store temporary data.
  • Files here are usually deleted on reboot.

15. /proc — Process Information

  • A virtual filesystem in memory that provides real-time info about the kernel and running processes.
  • Examples:
    • /proc/cpuinfo → CPU details
    • /proc/meminfo → Memory info
    • /proc/1/ → Process with PID 1

Conclusion

The Linux filesystem is like a living map of your system every file, device, and process has its place. Once you understand this hierarchy, navigating and troubleshooting Linux becomes far easier. 🧭🐧

Top comments (0)