DEV Community

Cover image for πŸ“‚ Understanding the Linux Filesystem Hierarchy – A Complete Guide πŸš€
Satyam Ahirrao
Satyam Ahirrao

Posted on

44 1

πŸ“‚ Understanding the Linux Filesystem Hierarchy – A Complete Guide πŸš€

When working with Linux, understanding the Filesystem Hierarchy Standard (FHS) is essential. Unlike Windows, which divides data into multiple drives (C:, D:, etc.), Linux follows a structured, single-rooted system. Let’s explore its core directories and their significance!


🌱 The Root Directory (/) – The Foundation of Linux

At the top of the hierarchy is /, the root directory. Every file and directory in Linux originates from this point. It contains all essential system directories, configuration files, and user data.

Everything in Linux is a file, whether it's a text document, a directory, a hardware device, or a running process.


πŸ“‚ Key Directories in Linux

1️⃣ /bin – Essential User Binaries πŸ’»

  • Stores essential system executables required for basic operations and booting.
  • Available for all users, even in single-user mode.
  • Examples: ls, cp, mv, grep, cat, echo, rm.

2️⃣ /sbin – System Binaries πŸ”§

  • Contains administrative commands for system management.
  • Requires root privileges to execute most commands.
  • Examples: shutdown, reboot, fsck, fdisk, iptables, mkfs.

3️⃣ /etc – Configuration Files βš™οΈ

  • Houses system-wide configuration files and scripts.
  • Modifying files here requires administrative privileges.
  • Examples:
    • /etc/fstab – Defines filesystem mount points.
    • /etc/passwd – Stores user account information.
    • /etc/hostname – Defines the system hostname.
    • /etc/network/interfaces – Manages network configurations.

4️⃣ /home – User Home Directories 🏠

  • Stores personal directories for each user.
  • Each user gets their own space: /home/username/.
  • Contains:
    • Documents πŸ“„
    • Downloads πŸ“₯
    • Pictures πŸ–ΌοΈ
    • Videos πŸŽ₯
    • .bashrc (custom shell configurations).

5️⃣ /root – Root User’s Home Directory 🌳

  • Dedicated home directory for the superuser (root).
  • Provides a secure workspace, separate from standard user directories.

⚠️ Never use root for daily tasks!


6️⃣ /var – Variable Data πŸ”„

  • Stores frequently changing files, such as logs, mail, and databases.
  • Examples:
    • /var/log/ – System and application logs πŸ“œ.
    • /var/spool/ – Mail queue & printer jobs πŸ“©πŸ–¨οΈ.
    • /var/cache/ – Temporary application cache data ⚑.

7️⃣ /tmp – Temporary Files πŸ—‘οΈ

  • Stores temporary files created by applications and the system.
  • Often cleared automatically on reboot.

8️⃣ /usr – User Applications & Libraries πŸ“š

A large directory divided into subdirectories:

  • /usr/bin/ – Common user applications (e.g., vim, nano, wget).
  • /usr/sbin/ – System administration binaries (e.g., apachectl).
  • /usr/local/ – Manually installed software.

9️⃣ /lib & /lib64 – System Libraries πŸ“¦

  • Holds shared libraries (.so files) required by binaries in /bin and /sbin.
  • Examples:
    • /lib/x86_64-linux-gnu/libc.so.6 – Standard C library.
    • /lib/modules/ – Kernel modules and drivers.

πŸ”Ÿ /opt – Optional Software 🌟

  • Used for third-party or manually installed software.
  • Common for commercial apps like Google Chrome, Oracle Java, and proprietary drivers.

1️⃣1️⃣ /mnt & /media – Mount Points πŸ–₯️

  • /mnt/ – Temporary mount point for system administrators.
  • /media/ – Auto-mounted external devices like USBs, CDs, and SD cards.

1️⃣2️⃣ /dev – Device Files πŸ”Œ

  • Special files representing hardware devices.
  • Examples:
    • /dev/sda – First hard drive. πŸ’Ύ
    • /dev/null – Discard anything written to it. πŸ—‘οΈ
    • /dev/random – Generates random data. 🎲

1️⃣3️⃣ /proc & /sys – Kernel & Process Information 🧠

  • /proc/ – A virtual file system with real-time system information.
    • Examples:
    • /proc/cpuinfo – CPU details. πŸ–₯️
    • /proc/meminfo – Memory usage. πŸ’Ύ
    • /proc/[PID] – Process details.
  • /sys/ – Exposes kernel and hardware configurations.

1️⃣4️⃣ /run – Runtime Data ⚑

  • Stores system-wide runtime data (e.g., PIDs, sockets).
  • Data here is deleted on reboot.

1️⃣5️⃣ /srv – Service Data πŸ—οΈ

  • Stores data for system services (e.g., web servers, FTP).
  • Example: /srv/http/ for a web server’s root directory.

1️⃣6️⃣ /lost+found – Recovered Files πŸ› οΈ

  • Used by the fsck utility for recovering lost files.
  • Appears in each partition with a Linux filesystem.

🎯 Why Understanding the Linux Filesystem Matters?

βœ… Better system navigation – Move around efficiently.

βœ… Enhanced troubleshooting skills – Fix errors quickly.

βœ… Security awareness – Prevent unauthorized modifications.

βœ… Performance optimization – Manage resources effectively.


πŸ“Œ Conclusion 🎯

The Linux file system is structured for organization, security, and efficiency. Whether you're a beginner or an expert, mastering this hierarchy will make you a better Linux user!

πŸ› οΈ Keep exploring, keep learning! πŸš€

Top comments (6)

Collapse
 
alexeipetrov908 profile image
Alexei Petrov β€’

Great article! This deep dive into the Linux file hierarchy really clarifies how everything is organized. I especially appreciate the explanations of the less common directories like /proc and /sys. It's much easier to navigate and troubleshoot now. Thanks for sharing this valuable resource!

Looking to optimize your business processes? Hire skilled Odoo programmers to customize and develop your Odoo ERP solution. They can tailor the platform to your specific workflows, integrate essential modules, and create custom functionalities. Finding the right Odoo developers is crucial for maximizing your ROI and achieving seamless operations. Elevate your business with a perfectly tailored Odoo system.

Collapse
 
dionisiodev profile image
Dionisio β€’

Thank you. I learned something here!

Collapse
 
nadeem_zia_257af7e986ffc6 profile image
nadeem zia β€’

Nice one...

Collapse
 
vinhchis profile image
Vinh Chi β€’

Nice

Collapse
 
kaellandrade profile image
Micael Andrade β€’

Very nice!

Collapse
 
it1995 profile image
FengFanChen β€’

Thanks for your teaching. It benefits me. In your article, I quite agree with the sentence "Keep exploring, keep learning!"

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay