mooc-course.com is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

Linux File Hierarchy Structure

Linux File Hierarchy Structure

5/5 - (1 vote)

The Linux File Hierarchy Structure (FHS) is a standardized directory layout for Unix-like operating systems. It defines the structure and contents of directories in the root filesystem, providing consistency across different Linux distributions. Understanding the FHS is crucial for efficient system administration, troubleshooting, and software development on Linux systems.

Root Directory (/)

The root directory is the top-level directory in the Linux filesystem hierarchy. All other directories and files branch out from this starting point.

Purpose: Serves as the primary hierarchy root and the root directory of the entire file system.

Contents:

  • All essential directories (bin, etc, home, var, etc.)
  • Mount points for other filesystems

Example: To list contents of the root directory:

ls /

/bin (Essential User Binaries)

Purpose: Contains essential command binaries that need to be available in single-user mode.

Contents:

  • Basic system commands (ls, cp, mv)
  • Shell interpreters (bash, sh)

Example: The ‘ls’ command is typically found here:

/bin/ls

/boot (Boot Loader Files)

Purpose: Contains files needed for booting the system.

Contents:

  • Kernel images
  • Initial RAM disk (initrd)
  • Boot loader configuration (GRUB)

Example: Kernel image file:

/boot/vmlinuz-5.4.0-42-generic

/dev (Device Files)

Purpose: Contains device files that represent hardware devices and virtual devices.

See also  How to Allow Chrome to Run in Background in Linux Mint

Contents:

  • Hard drive partitions (sda1, sdb1)
  • Terminals (tty1, tty2)
  • Null device (/dev/null)

Example: To write to the null device:

echo "discard this" > /dev/null

/etc (Configuration Files)

Purpose: Contains system-wide configuration files.

Contents:

Example: Network interfaces configuration:

/etc/network/interfaces

/home (User Home Directories)

Purpose: Contains personal directories for regular users.

Contents:

  • User-specific files and folders
  • Personal configuration files (dotfiles)

Example: A user’s home directory:

/home/username

/lib (Essential Shared Libraries)

Purpose: Contains libraries needed by the binaries in /bin and /sbin.

Contents:

Example: C library:

/lib/x86_64-linux-gnu/libc.so.6

/media (Removable Media)

Purpose: Mount point for removable media like CD-ROMs, and USB drives.

Contents:

  • Automatically mounted removable devices

Example: A mounted USB drive:

/media/username/USB_DRIVE

/mnt (Temporary Mount Points)

Purpose: Used for temporarily mounting filesystems.

Contents:

  • Manually mounted filesystems

Example: Mounting a network share:

mount //server/share /mnt/networkshare

/opt (Optional Software)

Purpose: Contains add-on application software packages.

Contents:

  • Third-party software installations

Example: A custom software installation:

/opt/myapp

/proc (Process Information)

Purpose: Virtual filesystem providing process and kernel information.

Contents:

  • Process information
  • System statistics

Example: To view CPU info:

cat /proc/cpuinfo

/root (Root User Home)

Purpose: Home directory for the root user.

Contents:

  • Root user’s files and configurations

/run (Run-time Variable Data)

Purpose: Contains variable data files describing the running system since the last boot.

Contents:

  • System information that is lost on reboot
  • PID files

Example: System’s uptime:

cat /run/utmp

/sbin (System Binaries)

Purpose: Contains essential system binaries that are used for system administration.

See also  Top OpenShot Alternatives for Linux Mint Users

Contents:

  • System management commands
  • Disk management utilities

Example: The ‘fdisk’ command:

/sbin/fdisk

/srv (Service Data)

Purpose: Contains data for services provided by the system.

Contents:

  • Web server files
  • FTP files

Example: Web server root:

/srv/www

/tmp (Temporary Files)

Purpose: Directory for temporary files.

Contents:

  • Temporary files created by the system and users
  • Cleared on system reboot

Example: Creating a temporary file:

echo "temp data" > /tmp/tempfile

/usr (User Programs)

Purpose: Contains user programs and data.

Contents:

  • Non-essential binaries (/usr/bin)
  • Libraries (/usr/lib)
  • Documentation (/usr/share/doc)

Example: A user command:

/usr/bin/git

/var (Variable Data)

Purpose: Contains variable data files.

Contents:

  • Log files (/var/log)
  • Spool directories (/var/spool)
  • Temporary files (/var/tmp)

Example: System log file:

/var/log/syslog

Recent Changes to FHS

The FHS has evolved to accommodate modern Linux systems. Notable changes include:

  1. Addition of /run directory: Introduced to store volatile runtime data, replacing /var/run and /var/lock.
  2. Consolidation of /bin, /sbin, /lib, and /lib64 into /usr: Some distributions now symlink these directories to their counterparts in /usr for better organization.
  3. Introduction of /sys: A virtual filesystem for kernel and device information, similar to /proc.

Understanding the Linux File Hierarchy Structure is essential for effective system management and troubleshooting. By following this standardized layout, Linux maintains consistency across distributions, making it easier for users, administrators, and developers to navigate and manage the system efficiently.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Free Worldwide Courses

Learn online for free

Enroll in Multiple Courses

Learn whatever your want from anywhere, anytime

International Language

Courses offered in multiple languages & Subtitles

Verified Certificate

Claim your verified certificate