Linux File Hierarchy Structure Explained: From Root to Home

What are the Different Types of Files in Linux?

  1. General Files – It is also called ordinary files. It may be an image, video, program, or simple text file. These types of files can be in ASCII or Binary format. It is the most commonly used file in the Linux system.
  2. Directory Files – These types of files are a warehouse for other file types. It may be a directory file within a directory (subdirectory).
  3. Device Files – In a Windows-like operating system, devices like CD-ROM, and hard drives are represented as drive letters like F: G: H whereas in the Linux system devices are represented as files. As for example, /dev/sda1, /dev/sda2, and so on.

What is the Linux File Hierarchy Structure?

In Linux everything is a file, files are file, directories are files, even devices are files. Thus, files must be managed properly to make the OS work efficiently.

The Linux File Hierarchy Structure (FHS) is a standardized system that defines how files and directories are organized within Linux and other Unix-like operating systems. The Linux Foundation maintains the Linux File Hierarchy Structure.

  • Root Directory (/) is the starting point in FHS, all directories appear under the root directory, even if they are stored on different physical/virtual devices.
  • Many directories (in FHS) are present in nearly all Unix-like operating systems and typically serve similar functions, even though the FHS is not considered authoritative for platforms other than Linux.
  • Some directories only exists when certain subsystems or application (such as X Windows System) are installed.

Directories in Linux File Hierarchy Structure (FHS)-

1. Root Directory “(/)”
  • The root directory is the starting point of the filesystem hierarchy.
  • All other directories are organized beneath it, creating a tree-like structure.
  • The /root directory is the home directory of root user which is different from / (Root Directory).
2. /bin
  • Contains binary executable files.
  • Contains essential commands that are available for all users, regardless of their shell or environment such as `ls`, `cp`, `mv`, etc.
  • Programs in this directory are often used for system recovery and maintenance.
3. /boot
  • Stores bootloader files, including the Linux kernel and initial ramdisk.
  • Contains configuration files for the bootloader (like GRUB).
  • Important for the system’s startup process, enabling the loading of the operating system.
4. /dev
  • Acts as an interface to the kernel’s device drivers, representing hardware devices as files.
  • Includes special files for devices like hard drives, USB drives, and terminals.
  • Allows applications to read from and write to hardware devices as if they were regular files.
5. /etc
  • Contains configuration files for the operating system and various applications such as  `passwd`, `hosts`, etc.
  • Files are typically plain text and can be edited by system administrators.
  • Also contains startup and shutdown shell scripts files used to start/stop individual programs.
6. /home
  • The designated directory for user home folders, providing a personal space for each user.
  • Users store their personal files, settings, and application data here.
  • Subdirectories for each user are named after their username (e.g., `/home/alice`).
7. /lib
  • Stores essential shared libraries required for the binaries in `/bin` and `/sbin` to function.
  • Contains kernel modules that extend the capabilities of the kernel.
  • Libraries are used by applications for common functions to reduce redundancy.
8. /media
  • Serves as a mount point for removable media devices such as USB drives, CDs, and DVDs.
  • Automatically populated when devices are plugged in, making it easy for users to access external storage.
  • Provides a standardized location for mounting and accessing media.
9. /mnt
  • A generic mount point for temporarily mounting filesystems, such as network shares or external drives.
  • Typically used by system administrators for temporary access during maintenance tasks.
  • Users can create subdirectories here for specific mount points.
10. /opt
  • Used for the installation of optional software packages that are not part of the default system installation.
  • Often contains third-party applications and add-ons.
  • Helps keep optional software separate from the standard filesystem hierarchy.
11. /proc
  • A virtual filesystem that provides real-time information about the system and running processes.
  • Allows users and applications to access kernel and system information dynamically.
  • Contains information about running processes. For example: /proc/{pid} directory contains information about the process with that particular pid.
12. /root
  • The home directory specifically for the root user, who has administrative privileges.
  • Separate from user directories under `/home` to enhance security.
  • Contains configuration files and personal settings for the system administrator.
13. /run
  • A temporary filesystem that holds runtime data and information since the last boot.
  • Stores PID files, sockets, and other transient data needed by the system and services.
  • Typically cleared on reboot, making it suitable for volatile data.
14. /srv
  • Contains data for services provided by the system, such as web server content or FTP files.
  • Helps organize service-related data, promoting clarity and accessibility.
  • Often structured to reflect the specific services running on the server.
15. /sys
  • A virtual filesystem that provides access to kernel data structures and allows interaction with kernel subsystems.
  • Enables users to inspect and modify kernel parameters at runtime.
  • Useful for hardware configuration and system performance tuning.
16. /tmp
  • A temporary directory for storing transient files created by applications and processes.
  • Files in `/tmp` are usually deleted upon system reboot to free up space.
  • Allows programs to store temporary data without cluttering user directories.
17. /usr
  • Contains user-related programs, libraries, and documentation.
  • Structured into subdirectories like `/usr/bin` (user binaries), `/usr/lib` (libraries), and `/usr/share` (shared resources).
  • Typically includes applications that are not required for basic system operation but are useful for users.
18. /var
  • Holds variable data files that change in size or content, such as logs, databases, and spool files.
  • Important for storing data generated by applications, ensuring system stability and performance.
  • Common subdirectories include `/var/log` (log files) and `/var/mail` (mail spool).
19 /sbin
  • Just like /bin, /sbin also contains binary executables.
  • The linux commands located under this directory are used typically by system administrators, for system maintenance purposes.
  • Example: iptables, reboot, fdisk, ifconfig, swapon

These are the most commonly found and widely used directories in the Linux File Hierarchy System, but there can be more directories depending on the subsystems/applications installed and the Operating System (Distro) used.

Leave a Comment