Post thumbnail
WEB DEVELOPMENT

The Linux Filesystem: Everything You Need to Know

By Vennilavan V

The Linux filesystem can be a harder one for understanding beginners. With its deep directory structure and unfamiliar folder names, it’s easy to get lost. But once you understand the purpose of each directory, everything starts to make sense.

In this blog, we’ll break down the most important directories in Linux and explain what’s inside each one.

Table of contents


  1. The Root Directory in Linux Filesystem
    • /bin and /sbin – Essential Binaries
    • /boot – Boot Files
    • /dev – Device Files
    • /etc – Configuration Files
    • /home – User Home Directories
    • /lib and /lib64 – Libraries
    • /mnt and /media – Mount Points
    • /opt – Optional Software
    • /tmp – Temporary Files
    • /usr – User Programs and Data
    • /var – Variable Files
    • /proc and /sys – Kernel and System Information
  2. Conclusion

The Root Directory in Linux Filesystem

At the top of the Linux filesystem hierarchy is the root directory, represented by a single forward slash (/). Every single file and directory on a Linux system is stored under this directory, regardless of where they reside on the disk.

Let’s break down the key directories you’ll find under / and explore their purposes.

1. /bin and /sbin – Essential Binaries

The /bin directory contains essential binaries (programs) that are needed for the system to boot and run basic tasks. These binaries are available to all users.

  • Common files:
    • /bin/bash: The bash shell, which most users interact with in the terminal.
    • /bin/ls: The command used to list files.

The /sbin directory is similar to /bin, but it contains system binaries that are typically reserved for the root user, such as those used for system administration

2. /boot – Boot Files

The /boot directory contains everything the system needs to boot, including the Linux kernel and bootloader files.

  • Common files:
    • /boot/vmlinuz: The Linux kernel.
    • /boot/grub/: Files for the GRUB bootloader.

You should be cautious when modifying files in /boot, as mistakes can make your system unbootable.

3. /dev – Device Files

Linux treats everything as a file, including devices like hard drives, keyboards, and printers. The /dev directory contains special files that represent these devices.

  • Common files:
    • /dev/sda: The first hard drive in the system.
    • /dev/null: A virtual device that discards anything written to it.

Programs interact with hardware by reading and writing to these device files.

4. /etc – Configuration Files

The /etc directory is home to all system-wide configuration files. These files control how various software and services behave on your system.

  • Common files:
    • /etc/passwd: Contains user account information.
    • /etc/hostname: Defines the system’s network hostname.
    • /etc/fstab: Configuration for automatic mounting of file systems.

Everything in /etc is crucial for system configuration, and manually editing these files can affect how your Linux system operates.

5. /home – User Home Directories

Each user on a Linux system has their personal space under the /home directory. For example, if your username is ubuntu, your home directory would be /home/ubuntu/. This is where users store their personal files, settings, and projects.

  • Common contents:
    • /home/username/Documents: Personal documents.

Files in /home are specific to each user and typically not shared between users, unless explicitly permitted.

6. /lib and /lib64 – Libraries

The /lib and /lib64 directories contain essential shared libraries required by binaries in /bin and /sbin. These libraries help programs perform basic functions and interface with hardware.

  • Common libraries:
    • /lib/x86_64-linux-gnu/libc.so.6: The GNU C Library, used by many programs.
    • /lib/modules/: Kernel modules, which extend the functionality of the kernel.

7. /mnt and /media – Mount Points

The /mnt and /media directories are used for mounting file systems such as USB drives, CD-ROMs, or external hard drives.

  • Difference between /mnt and /media:
    • /mnt: A general-purpose directory for mounting file systems temporarily.
    • /media: Typically used by the system to automatically mount external drives, like USBs or CDs, under subdirectories such as /media/ubuntu/usb-drive.

8. /opt – Optional Software

The /opt directory is used for third-party software packages that aren’t included with the operating system. These are often large, self-contained programs or suites.

  • Use cases:
    • Software like Google Chrome, proprietary drivers, or specialized software that isn’t installed through the system package manager.
MDN

9. /tmp – Temporary Files

The /tmp directory is used for temporary files created by programs. Files stored here are not meant to be persistent and can be deleted at any time, often when the system reboots.

  • Use cases:
    • Temporary storage for downloads or installation processes.
    • Temporary session files for applications.

Because /tmp is publicly writable, it’s often used as scratch space by various system services.

10. /usr – User Programs and Data

The /usr directory holds the bulk of user-installed programs and their related data, which is why it’s often one of the largest directories on a Linux system.

  • Common directories inside /usr:
    • /usr/bin/: Contains most user-executable programs.
    • /usr/lib/: Shared libraries needed by programs in /usr/bin/.
    • /usr/share/: Architecture-independent files such as documentation, icons, and default configuration.

It’s important to note that /usr does not stand for “user”, but rather “Unix System Resources.”

11. /var – Variable Files

The /var directory is used for files that are expected to grow in size over time. This includes log files, caches, and spool files for tasks like printing and mail queues.

  • Common files:
    • /var/log/: Stores log files for system events and services.
    • /var/tmp/: Temporary files that are persistent across reboots.
    • /var/lib/: Stores data used by programs (e.g., databases).

The size of /var can grow significantly depending on how your system is used. Regular maintenance, like clearing old logs, is crucial for managing space.

12. /proc and /sys – Kernel and System Information

The /proc and /sys directories are virtual filesystems that provide information about the kernel and running processes.

  • In /proc:
    • /proc/cpuinfo: Information about the CPU.
    • /proc/meminfo: Information about memory usage.
  • In /sys:
    • /sys/class/net/: Network devices.
    • /sys/devices/: Detailed information about system devices.

These directories don’t contain actual files on the disk. Instead, they provide a view of the system’s running state.

MDN

Conclusion

The Linux file system hierarchy may seem confusing at first glance, but each directory serves a specific purpose. As you spend more time with the system, navigating and managing files will become second nature.

Happy exploring!

Career transition

Did you enjoy this article?

Schedule 1:1 free counselling

Similar Articles

Loading...
Share logo Copy link
Free Webinar
Free Webinar Icon
Free Webinar
Get the latest notifications! 🔔
close
Table of contents Table of contents
Table of contents Articles
Close button

  1. The Root Directory in Linux Filesystem
    • /bin and /sbin – Essential Binaries
    • /boot – Boot Files
    • /dev – Device Files
    • /etc – Configuration Files
    • /home – User Home Directories
    • /lib and /lib64 – Libraries
    • /mnt and /media – Mount Points
    • /opt – Optional Software
    • /tmp – Temporary Files
    • /usr – User Programs and Data
    • /var – Variable Files
    • /proc and /sys – Kernel and System Information
  2. Conclusion