Linux Directory Structure Reference Guide
Last updated on
Simple reference guide for Linux directories and their use
* AI Generated
Overview
The Linux filesystem follows a hierarchical structure defined by the Filesystem Hierarchy Standard (FHS). Understanding this structure is essential for system administration, software deployment, and general Linux usage.
Root Directory Structure
/ (Root Directory)
The top-level directory that contains all other directories and files in the system.
Essential System Directories
/bin - Essential User Binaries
- Purpose: Contains essential command-line utilities needed by all users
- Availability: Must be available even in single-user mode
- Examples:
ls,cp,mv,cat,bash,grep - Note: These are commands you’d expect to work on any Linux system
/sbin - System Binaries
- Purpose: Essential system administration commands
- Access: Typically used by root/administrators
- Examples:
mount,umount,fsck,iptables,systemctl - Note: “s” stands for “system” or “superuser”
/lib - Essential Libraries
- Purpose: Shared libraries required by programs in
/binand/sbin - Contents: Dynamic linking libraries (.so files)
- Importance: Critical for system boot and basic functionality
User and Application Directories
/usr - User System Resources
Secondary hierarchy containing the majority of user utilities and applications.
Key subdirectories:
/usr/bin- Non-essential user commands and applications/usr/sbin- Non-essential system administration binaries/usr/lib- Libraries for/usr/binand/usr/sbinprograms/usr/local- Local software installations (not from package manager)/usr/share- Architecture-independent shared data
/opt - Optional Software Packages
- Purpose: Self-contained third-party software packages
- Structure: Each package gets its own subdirectory (e.g.,
/opt/google/chrome) - Use Cases:
- Commercial software
- Large application suites
- Proprietary applications
- Software that prefers to keep all files together
- Examples: Oracle Database, VMware, Google Chrome, custom enterprise applications
/home - User Home Directories
- Purpose: Personal directories for regular users
- Structure:
/home/username - Contents: User files, personal configurations, documents
/root - Root User Home
- Purpose: Home directory specifically for the root user
- Location: Separate from
/homefor security and availability reasons
Configuration and Data Directories
/etc - System Configuration
- Purpose: System-wide configuration files
- Format: Text-based configuration files
- Examples:
/etc/passwd,/etc/hosts,/etc/apache2/,/etc/ssh/ - Scope: Affects entire system, not individual users
/var - Variable Data
- Purpose: Files that change during normal system operation
- Key subdirectories:
/var/log- System and application log files/var/mail- User mailboxes/var/tmp- Temporary files preserved between reboots/var/lib- Application state data/var/cache- Application cache data
Temporary and Runtime Directories
/tmp - Temporary Files
- Purpose: Temporary files for applications and users
- Cleanup: Often cleared on system reboot
- Access: World-writable with sticky bit set
- Usage: Short-term storage during program execution
Boot and Hardware Directories
/boot - Boot Files
- Purpose: Files required for system startup
- Contents: Kernel images, initial RAM disk, bootloader configuration
- Examples:
vmlinuz,initrd.img, GRUB configuration
/dev - Device Files
- Purpose: Special files representing hardware devices
- Type: Character and block device files
- Examples:
/dev/sda(hard drive),/dev/null,/dev/random - Management: Usually managed automatically by
udev
Virtual Filesystems
/proc - Process Information
- Purpose: Virtual filesystem exposing kernel and process information
- Contents: Process directories (numbered by PID), system information
- Examples:
/proc/cpuinfo,/proc/meminfo,/proc/1/(init process) - Note: Files exist only in memory, not on disk
/sys - System Information
- Purpose: Virtual filesystem for modern kernel object information
- Contents: Hardware device information, kernel modules, power management
- Usage: Used by modern system management tools
- Note: More structured than
/proc
Mount Point Directories
/mnt - Manual Mount Point
- Purpose: Temporary mount point for manually mounted filesystems
- Usage: System administrators mount filesystems here temporarily
- Examples: Mounting external drives for maintenance
/media - Removable Media
- Purpose: Automatic mount points for removable media
- Management: Usually handled by desktop environments
- Examples:
/media/usb-drive,/media/cdrom
Quick Reference Summary
| Directory | Primary Purpose | Key Characteristics |
|---|---|---|
/bin | Essential user commands | Available in single-user mode |
/sbin | System administration | Root/admin tools |
/usr | User programs and data | Secondary hierarchy |
/opt | Third-party packages | Self-contained installations |
/etc | System configuration | Text-based config files |
/var | Changing data | Logs, mail, temporary files |
/home | User directories | Personal user spaces |
/tmp | Temporary files | Often cleared on boot |
Best Practices for Students
- Exploration: Use
ls -lato explore directory contents and permissions - Documentation: Check
man hierfor detailed filesystem hierarchy information - Respect: Be cautious when working in system directories (especially as root)
- Understanding: Learn the logic behind the structure - it makes navigation intuitive
- Practice: Set up a virtual machine to safely explore the filesystem structure
Common Confusion Points
/usrvs/usr/local:/usris for package-managed software,/usr/localis for manually compiled/installed software/binvs/usr/bin:/binis for essential commands,/usr/binis for additional user programs/tmpvs/var/tmp:/tmpmay be cleared on reboot,/var/tmpshould persist across reboots/optvs/usr/local: Both for additional software, but/optis for packaged applications,/usr/localfollows standard hierarchy
This structure has evolved over decades and represents a balance between organization, tradition, and practical system administration needs.