File System Hierarchy (/bin, /etc, /var, /usr, /home, /tmp, etc.)

The Linux File System Hierarchy Standard (FHS) defines the structure and organization of directories in Linux systems. Understanding this hierarchy is essential for system administration, troubleshooting, and efficient navigation. This guide explores each major directory and its purpose.

Linux File System Hierarchy Overview

/ (root)
├── bin - Essential user binaries
├── boot - Boot loader files
├── dev - Device files
├── etc - System configuration files
├── home - User home directories
├── lib - Essential shared libraries
├── media - Removable media mount points
├── mnt - Temporary mount points
├── opt - Optional software packages
├── proc - Process and kernel information
├── root - Root user's home
├── run - Runtime variable data
├── sbin - System administration binaries
├── srv - Service data
├── tmp - Temporary files
├── usr - User programs and data
└── var - Variable data

Essential System Directories

/bin

Essential User Binaries

Contains essential command binaries needed for system boot and repair.

Contents:

  • Basic commands: ls, cp, mv, rm, cat
  • Shells: bash, sh
  • File utilities: grep, find, tar
  • System utilities: kill, ps, mount

Example: /bin/ls, /bin/bash

🛠️
/sbin

System Administration Binaries

Contains binaries for system administration and maintenance.

Contents:

  • System control: init, shutdown, reboot
  • Network utilities: ifconfig, route
  • Filesystem tools: fsck, mkfs
  • System daemons: udevd, syslogd

Note: Typically requires root privileges

📋
/etc

System Configuration Files

Host-specific system configuration files and directories.

Contents:

  • System config: /etc/passwd, /etc/group
  • Service config: /etc/ssh/sshd_config
  • Network config: /etc/network/interfaces
  • Package config: /etc/apt/sources.list

Example: /etc/hosts, /etc/fstab

User and Application Directories

🏠
/home

User Home Directories

Contains personal directories for each user account.

Structure:

  • /home/username/ - Individual user directories
  • User config files: ~/.bashrc, ~/.ssh/
  • Personal documents, downloads, etc.
  • Application settings and caches

Example: /home/john/, /home/sarah/

💻
/usr

User Programs and Data

Contains the majority of user utilities and applications.

Subdirectories:

  • /usr/bin - Most user commands
  • /usr/sbin - Non-essential system admin
  • /usr/lib - Libraries
  • /usr/share - Architecture-independent data
  • /usr/local - Locally installed software

Example: /usr/bin/python3

📦
/opt

Optional Software Packages

Contains add-on application software packages.

Contents:

  • Third-party commercial software
  • Large applications with their own structure
  • Software not included in distribution packages
  • Each package in its own subdirectory

Example: /opt/google/chrome/

Variable and Temporary Data

📊
/var

Variable Data

Contains files that change during system operation.

Subdirectories:

  • /var/log - System and application logs
  • /var/cache - Application cache data
  • /var/spool - Queued items (print, mail)
  • /var/www - Web server documents (Apache)
  • /var/lib - Application state information

Example: /var/log/syslog

🗑️
/tmp

Temporary Files

Contains temporary files created by system and users.

Characteristics:

  • Automatically cleaned on reboot
  • World-writable (sticky bit set)
  • Used for temporary storage
  • Applications create session files here

Permissions: drwxrwxrwt (note the 't')

⚙️
/proc

Process Information

Virtual filesystem providing process and system information.

Contents:

  • /proc/[pid] - Individual process info
  • /proc/cpuinfo - CPU information
  • /proc/meminfo - Memory information
  • /proc/mounts - Mounted filesystems
  • /proc/net/ - Network statistics

Example: cat /proc/meminfo

Special Purpose Directories

Directory Purpose Key Contents Notes
/boot Boot loader files Kernel, initramfs, GRUB Essential for system boot
/dev Device files /dev/sda, /dev/tty, /dev/null Hardware device interfaces
/lib Essential libraries Shared libraries for /bin and /sbin Required for system boot
/media Removable media CD-ROM, USB drives mount points Automatically mounted
/mnt Temporary mounts Manual filesystem mounts System admin use
/root Root user home Root's personal files Not in /home for boot reasons
/srv Service data Data for services (FTP, HTTP) Site-specific data
/run Runtime data Process IDs, lock files tmpfs (in-memory)
Memory-Based Filesystems:
/proc - Virtual filesystem for process information
/sys - Virtual filesystem for kernel objects
/run - Temporary filesystem for runtime data
/dev/shm - Shared memory (tmpfs)

/usr Directory Structure

/usr
├── bin - Most user commands
├── sbin - Non-essential system admin
├── lib - Libraries
├── include - Header files for C programs
├── share - Architecture-independent data
│ ├── man - Manual pages
│ ├── doc - Documentation
│ └── locale - Localization data
├── src - Source code
└── local - Local software
├── bin - Local binaries
├── lib - Local libraries
└── share - Local data

/var Directory Structure

/var
├── log - Log files
│ ├── syslog - System log
│ ├── auth.log - Authentication log
│ └── apache2/ - Web server logs
├── cache - Cache data
│ └── apt/ - Package cache
├── spool - Queued tasks
│ ├── cron/ - Scheduled jobs
│ ├── mail/ - Mail queues
│ └── lpd/ - Print queues
├── lib - State information
│ └── mysql/ - Database files
└── www - Web content
└── html - HTML documents

Practical Navigation Examples

Exploring the File System

# 1. Navigate and explore key directories
cd /
ls -l

# 2. Check system configuration
ls -l /etc/
cat /etc/hostname
cat /etc/passwd | head -5

# 3. Explore user programs
ls /usr/bin | wc -l  # Count available commands
which python3
ls -l /usr/bin/python*

# 4. Check system logs
sudo ls -l /var/log/
sudo tail -f /var/log/syslog

# 5. Examine process information
cat /proc/meminfo
cat /proc/cpuinfo | grep "model name"
ls /proc/ | head -10

# 6. Check mounted filesystems
cat /proc/mounts
df -h

# 7. Explore device files
ls -l /dev/sd*  # Storage devices
ls -l /dev/tty*  # Terminal devices

# 8. Check temporary space
ls -l /tmp/
df -h /tmp

Important Configuration Files

System Configuration:
/etc/passwd - User account information
/etc/group - Group definitions
/etc/shadow - Secure user passwords
/etc/hosts - Static hostname lookup
/etc/fstab - Filesystem mount table
/etc/ssh/sshd_config - SSH server configuration

Network Configuration:
/etc/network/interfaces - Network interfaces (Debian)
/etc/sysconfig/network-scripts/ - Network scripts (RHEL)
/etc/resolv.conf - DNS resolver configuration
/etc/hostname - System hostname

Package Management:
/etc/apt/sources.list - APT repository sources
/etc/yum.repos.d/ - YUM repository configurations
Important Security Notes:
• Never delete files from system directories unless you're certain
• Backup configuration files before making changes
• Use package managers (apt, yum) for software installation/removal
• Be cautious with /tmp - files are automatically deleted on reboot
• /proc and /sys are virtual - don't store permanent data there

Best Practices

File System Organization Tips

  • User Data: Store personal files in /home/username/
  • System Config: Modify files in /etc/ for system-wide changes
  • Local Software: Install custom software in /usr/local/
  • Log Files: Check /var/log/ for troubleshooting
  • Temporary Files: Use /tmp/ for short-lived files
  • Web Content: Place website files in /var/www/ or /srv/
  • Backup Strategy: Focus on /etc, /home, /var for backups

Common Mistakes to Avoid

  • Don't store personal files in system directories
  • Avoid manual file deletion from /bin, /sbin, /lib
  • Don't run applications as root unnecessarily
  • Avoid filling /tmp with large permanent files
  • Don't modify files in /proc or /sys directly
  • Use package managers instead of manual compilation when possible

Key Takeaways

The Linux File System Hierarchy provides a standardized structure that ensures consistency across distributions. Understanding the purpose of each directory (/bin for essential binaries, /etc for configuration, /var for variable data, /home for user files, etc.) is crucial for effective system administration, troubleshooting, and development. This organization separates system files from user data, static files from variable data, and essential components from optional software.

Next Step: Explore Linux package management to understand how software is installed, updated, and maintained in different distributions.