Linux 101: Part 2 - Understanding the Linux File System

Himanshu Bhatt - Feb 15 - - Dev Community

Understanding the Linux File System: A Deep Dive

The Linux File System is a hierarchical structure where each file and directory has a specific role. It’s essential to understand these directories and their subdirectories for effective Linux system administration. In this post, we’ll explore all the major directories in the Linux file system and their subdirectories to give you a clear understanding of their roles and purposes.

Linux File System Diagram

1. / (Root Directory)

The root directory is the topmost directory in the Linux file system hierarchy. All other directories are branches stemming from the root. It's the starting point of the system, and everything in Linux is contained within this directory, directly or indirectly.


2. /bin (Binary Files)

The /bin directory contains essential binary files (executables) that are needed to boot the system and perform essential tasks. These binaries are available to all users, including single-user mode.

  • Examples: ls, cp, mv, cat

Subdirectories:

  • No direct subdirectories under /bin. It only contains binary files essential for basic operations.

3. /boot (Boot Loader Files)

The /boot directory contains files required for booting the Linux system. It holds the kernel and other files that the boot loader uses to load the operating system into memory.

  • Examples: vmlinuz (Linux kernel), initrd.img (initial RAM disk), grub/ (GRUB bootloader files)

Subdirectories:

  • /boot/grub/: Contains configuration files for the GRUB bootloader, like grub.cfg.

4. /dev (Device Files)

The /dev directory contains device files. These files represent physical devices (e.g., hard drives, terminals, printers) and software interfaces. It provides access to the hardware on the system.

  • Examples: /dev/sda (first hard disk), /dev/tty (terminal devices), /dev/null (null device)

Subdirectories:

  • /dev/pts/: Contains pseudo-terminal devices, used for terminal sessions.
  • /dev/shm/: A temporary file storage filesystem for shared memory.

5. /etc (Configuration Files)

The /etc directory contains system-wide configuration files that define system settings. These files govern the behavior of the operating system and software applications.

  • Examples: /etc/passwd (user account information), /etc/fstab (file system table), /etc/network/interfaces (network configuration)

Subdirectories:

  • /etc/apt/: Contains configuration files for APT (Advanced Package Tool) used in Debian-based distributions.
  • /etc/systemd/: Contains systemd unit files for managing services and system settings.
  • /etc/init.d/: Stores startup scripts for services.

6. /home (User Directories)

The /home directory contains personal directories for each user. This is where individual users store their files, documents, and configuration settings. It’s separate from the system files to ensure user data is isolated and secure.

  • Examples: /home/john/, /home/alice/ (User directories)

Subdirectories:

  • /home/<username>/.config/: Stores user-specific application configuration files.
  • /home/<username>/Downloads/: A default location for downloaded files.

7. /lib (Shared Libraries)

The /lib directory contains shared library files that are essential for the functioning of binaries stored in /bin and /sbin. These libraries provide various functions to applications, such as file handling and memory management.

  • Examples: libc.so (C standard library), libpthread.so (POSIX threads library)

Subdirectories:

  • /lib/modules/: Contains kernel modules for adding support for additional hardware or functionality.
  • /lib64/: Contains 64-bit versions of shared libraries.

8. /media (Removable Media)

The /media directory is used for automatically mounting removable media such as USB drives, CDs, and DVDs. When a removable device is plugged in, it gets mounted under /media.

  • Examples: /media/usb/, /media/cdrom/

Subdirectories:

  • No further subdirectories within /media unless specific devices are mounted.

9. /mnt (Mount Points)

The /mnt directory is used for mounting temporary file systems and devices. It is typically used by system administrators for manual mounting tasks, such as mounting external hard drives or file systems during maintenance.

  • Examples: /mnt/usb/

Subdirectories:

  • No specific subdirectories within /mnt, unless manually created for mounted devices.

10. /opt (Optional Software)

The /opt directory is used for installing optional software or third-party applications. Software that doesn't belong to the default system setup, such as commercial software or large application suites, is often installed here.

  • Examples: /opt/google/, /opt/lampp/ (XAMPP stack)

Subdirectories:

  • /opt/<software>/: Software-specific subdirectories, such as /opt/google/chrome/ for the Google Chrome browser.

11. /root (Root User's Home)

The /root directory is the home directory for the root user, the system administrator. This directory is separate from /home to isolate administrative files and prevent accidental interference.

  • Examples: /root/

Subdirectories:

  • /root/.bashrc: Configuration file for the root user’s shell environment.
  • /root/.ssh/: Directory for storing SSH keys used for secure connections.

12. /sbin (System Binaries)

The /sbin directory contains system binaries essential for system administration tasks. These files are typically used by the root user or administrators for system management, such as system recovery or hardware configuration.

  • Examples: fsck, reboot, mount

Subdirectories:

  • No specific subdirectories under /sbin, but binaries are organized for system administration.

13. /srv (Service Data)

The /srv directory holds data for services provided by the system. For example, web server files or FTP server files are stored here.

  • Examples: /srv/www/ (web server files), /srv/ftp/ (FTP server files)

Subdirectories:

  • No typical subdirectories; used for storing service-specific data.

14. /tmp (Temporary Files)

The /tmp directory is used for storing temporary files. It is used by applications to store temporary data that may not need to persist after a reboot. Files here are often cleared on system reboot.

  • Examples: Temporary cache files, session files

Subdirectories:

  • No significant subdirectories, but used by apps for temporary storage.

15. /usr (User Programs)

The /usr directory contains user-related programs and data. It houses binaries, libraries, documentation, and various resources needed for system and user applications.

  • Examples: /usr/bin/ (user binaries), /usr/share/ (shared data)

Subdirectories:

  • /usr/bin/: Contains application binaries available for all users.
  • /usr/lib/: Contains libraries used by binaries in /usr/bin/.
  • /usr/include/: Contains header files needed for compiling programs.
  • /usr/sbin/: Contains system binaries used by the administrator, such as useradd and groupadd.

16. /var (Variable Data)

The /var directory contains files that are likely to change frequently, such as logs, caches, and spool files.

  • Examples: /var/log/ (log files), /var/cache/ (application cache)

Subdirectories:

  • /var/cache/: Contains cached data used by programs to improve performance.
  • /var/log/: Stores log files generated by system processes and applications.
  • /var/spool/: Holds data that is queued for processing, such as print jobs and email.
  • /var/tmp/: Temporary files that are preserved between reboots.

Conclusion

The Linux file system is a well-structured hierarchy that helps keep files organized and easily accessible. Each directory has a specific purpose, whether it’s for system binaries, user data, or configuration files. Understanding the function of each directory, and its subdirectories, is key to navigating and managing a Linux system effectively.

By becoming familiar with these directories, you’ll be better equipped to handle tasks like system administration, troubleshooting, and customization.


Got questions or need clarification? Drop a comment below! 🛠️

Stay updated with my latest blogs and tech insights! 🚀

Follow me on _himanshubhatt1 for more updates and future posts.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .