Loading...

Linux Filesystem Structure: Complete Directory Hierarchy Guide

Back to blog
LinuxFilesystemDevOpsSystem Administration

Linux Filesystem Structure: Complete Directory Hierarchy Guide

Master the Linux filesystem hierarchy from root (/) to /usr, /etc, /var, /home, and all major directories. Understand the FHS standard with practical examples.

10 min read

Linux Filesystem Structure: Complete Directory Hierarchy Guide

The Linux filesystem is organized according to the Filesystem Hierarchy Standard (FHS), which ensures consistency across different Linux distributions. Understanding this structure is fundamental for system administration, troubleshooting, and effective DevOps practices.

Root Directory (/)

The root directory is the starting point of the entire filesystem. All other directories branch out from here.

# View the root directory contents
ls -la /
 
# Output example:
# drwxr-xr-x   2 root root      4096 Jan 23 10:00 bin
# drwxr-xr-x   5 root root      1024 Jan 20 14:32 boot
# drwxr-xr-x   2 root root      4096 Jan 15 08:15 dev
# dr-xr-xr-x   3 root root      4096 Jan 23 11:45 etc
# drwxr-xr-x  20 root root      4096 Jan 22 16:20 home
# ... and more

Essential System Directories

/bin - Essential Command Binaries

Contains critical executable programs required for basic system functionality and recovery.

# View binaries available to all users
ls /bin | head -20
# ls, cat, echo, grep, chmod, mkdir, rm, etc.
 
# Check if a command is in /bin
which ls
# /bin/ls
 
# These commands are available to all users
cat /etc/passwd  # View user information
mkdir testdir    # Create a directory

/sbin - System Binaries

Contains system administration binaries. Typically accessible only by the root user.

# System administration commands
ls /sbin | head -20
# ip, ifconfig, iptables, fsck, mount, reboot, shutdown
 
# Example: Using system commands (requires sudo)
sudo ifconfig eth0
sudo ip link show
 
# View network interfaces
ip addr show

/etc - Configuration Files

The most important directory for administrators. Contains all system-wide configuration files.

# View directory structure
tree /etc -L 1
# /etc/
# ├── addgroup.conf
# ├── adduser.conf
# ├── bash.bashrc
# ├── environment
# ├── fstab
# ├── hostname
# ├── hosts
# ├── passwd
# ├── group
# ├── shadow
# ├── sudoers
# ├── ssh/
# ├── systemd/
# └── ... and many more
 
# View hostname configuration
cat /etc/hostname
# myserver
 
# View DNS configuration
cat /etc/resolv.conf
# nameserver 8.8.8.8
# nameserver 8.8.4.4
 
# View user database
cat /etc/passwd | head -5
# root:x:0:0:root:/root:/bin/bash
# daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
# bin:x:2:2:bin:/bin:/usr/sbin/nologin

/home - User Home Directories

Each regular user has a home directory here for personal files and configurations.

# List all users
ls -la /home/
# drwxr-xr-x 5 john  john  4096 Jan 23 15:20 john
# drwxr-xr-x 4 sarah sarah 4096 Jan 22 10:05 sarah
 
# Navigate to your home directory
cd ~
pwd
# /home/john
 
# View hidden configuration files in home
ls -la ~/
# .bashrc          - Bash shell configuration
# .profile         - Shell login configuration
# .ssh/            - SSH keys and config
# .config/         - Application configurations
# .local/          - User-specific data and applications
 
# Change to specific user's home
cd ~ubuntu
pwd
# /home/ubuntu

/root - Root User's Home

The home directory for the root user (system administrator).

# View root's home directory
sudo ls -la /root
# Only accessible with sudo privileges
 
# Switch to root and check directory
sudo -i
pwd
# /root
exit

/var - Variable Data

Contains data that frequently changes during system operation.

# View subdirectories
tree /var -L 2
 
# /var/log - System and application logs
ls /var/log
# syslog, auth.log, kern.log, messages, etc.
 
# View system logs
cat /var/log/syslog | tail -20
tail -f /var/log/syslog  # Follow logs in real-time
 
# View authentication logs
grep "Failed password" /var/log/auth.log
# Shows failed login attempts
 
# /var/www - Web server files
ls /var/www/
# html/
 
# /var/cache - Cache data
du -sh /var/cache/*
 
# /var/tmp - Temporary files (survives reboot)
ls /var/tmp/
 
# /var/mail - User mailboxes
ls /var/mail/

/usr - User Programs and Data

Contains user-facing programs, libraries, and documentation.

# View main subdirectories
ls -la /usr
# bin/      - User commands
# sbin/     - User system commands
# local/    - Locally installed software
# share/    - Architecture-independent data
# lib/      - Libraries
# include/  - Header files
 
# /usr/bin - Standard user applications
ls /usr/bin | head -20
# nano, vim, python3, node, docker, etc.
 
# /usr/local - Locally compiled/installed software
ls /usr/local/bin/
# Custom applications installed from source
 
# /usr/share - Man pages, documentation, etc.
ls /usr/share/
# doc/, man/, applications/, backgrounds/, etc.
 
# View available man pages
man -k "network"  # Search man pages
 
# /usr/include - C header files
ls /usr/include/ | head
# stdio.h, stdlib.h, sys/, etc.

/tmp - Temporary Files

Temporary files, cleared on system reboot.

# View temporary files
ls -la /tmp/
 
# Create temporary files
touch /tmp/mytemp.txt
echo "temporary data" > /tmp/tempdata.txt
 
# /tmp is world-writable
ls -ld /tmp
# drwxrwxrwt 12 root root 4096 Jan 23 16:50 /tmp
 
# View size of temporary files
du -sh /tmp/
 
# Clean old temporary files
find /tmp -type f -atime +30 -delete  # Delete files not accessed in 30 days

/opt - Optional Software Packages

Third-party applications installed outside the standard package system.

# View installed optional packages
ls /opt/
 
# Example structure
ls /opt/custom-app/
# bin/
# lib/
# share/
 
# Add to PATH for easy access
export PATH=$PATH:/opt/custom-app/bin

/boot - Boot Files

Contains the kernel and bootloader files.

# View boot directory
ls -la /boot/
 
# Kernel images
ls /boot/vmlinuz-*
 
# Initial RAM disk
ls /boot/initrd-*
 
# GRUB bootloader configuration
cat /boot/grub/grub.cfg | head -20

/dev - Device Files

Contains device files for hardware and pseudo-devices.

# View device files
ls /dev/ | head -20
 
# Common devices
ls /dev/sd*      # Hard drives (sda, sdb, etc.)
ls /dev/tty*     # Terminal devices
ls /dev/null     # Null device (discards all output)
ls /dev/zero     # Zero device (produces null bytes)
ls /dev/random   # Random number device
 
# Example: Discard output using /dev/null
ls /home > /dev/null
echo "This goes nowhere" > /dev/null
 
# Example: Get random bytes
head -c 100 /dev/urandom | od -An -tx1

/media and /mnt - Mounting Points

Directories for mounting removable media and temporary filesystems.

# /media - Removable media (USB, CD-ROM)
ls /media/
 
# /mnt - Temporary mount points
ls /mnt/
 
# Mount a device
sudo mount /dev/sdb1 /mnt/external
cd /mnt/external
 
# Unmount a device
sudo umount /mnt/external
 
# View currently mounted filesystems
mount
# /dev/sda1 on / type ext4 (rw,relatime)
# /dev/sda2 on /boot type ext4 (rw,relatime)
 
# Alternative: use findmnt
findmnt

/proc - Process Information

Virtual filesystem providing information about running processes and system status.

# View all processes
ls /proc/
 
# View details about a specific process (PID 1)
ls /proc/1/
 
# View command line of a process
cat /proc/1/cmdline | tr '\0' ' '
 
# View memory information
cat /proc/meminfo
# MemTotal:        8192000 kB
# MemAvailable:    4096000 kB
# MemFree:         2048000 kB
 
# View CPU information
cat /proc/cpuinfo | head -20
 
# View system uptime
cat /proc/uptime
# 123456.78 987654.32
 
# Convert to human readable
uptime
# 10 days, 10:45, 2 users, load average: 0.05, 0.10, 0.15

/sys - System and Device Information

Virtual filesystem for kernel and device information.

# View system information
ls /sys/
 
# Device information
ls /sys/devices/
 
# Block devices
ls /sys/block/
 
# Check device properties
cat /sys/block/sda/device/model
 
# Power information
cat /sys/class/power_supply/BAT0/capacity  # Battery percentage

/lib and /lib64 - System Libraries

Shared libraries required by system programs.

# View libraries
ls /lib/ | head -10
 
# C library
ls /lib/x86_64-linux-gnu/libc.so*
 
# View dependencies of a binary
ldd /bin/ls
# linux-vdso.so.1 (0x00007ffcc4dc9000)
# libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5a4a000000)
 
# Check library version
/lib64/ld-linux-x86-64.so.2 --version

Directory Navigation Commands

pwd - Print Working Directory

Shows the current directory path.

pwd
# /home/john/projects
 
# PWD environment variable
echo $PWD
# /home/john/projects

cd - Change Directory

Navigate between directories.

# Change to home directory
cd
pwd
# /home/john
 
# Change to specific directory
cd /etc/
pwd
# /etc
 
# Go to previous directory
cd -
pwd
 
# Go up one level
cd ..
pwd
 
# Go up two levels
cd ../..
pwd
 
# Use absolute path from anywhere
cd /var/log
cd /var/log/  # Same as above
 
# Change to root's home (with sudo)
sudo su -
pwd
# /root

ls - List Directory Contents

Display files and directories.

# Basic listing
ls /home/
 
# Detailed listing with permissions
ls -la /etc/ | head
 
# List with human-readable sizes
ls -lh /var/log/
 
# Sort by modification time (newest first)
ls -lt /tmp/ | head
 
# Show hidden files
ls -a ~/
# .bashrc, .config, .ssh, etc.
 
# Recursive listing
ls -R /usr/bin/ | head -30
 
# Show only directories
ls -d /etc/*/
 
# Show file types (/ for dirs, * for executables)
ls -F /bin/ | head

tree - Display Directory Tree

Visualize directory structure in a tree format.

# Install tree if not available
sudo apt-get install tree
 
# Basic tree view
tree /home/
 
# Limit depth
tree -L 2 /usr/
# Shows only 2 levels
 
# Show only directories
tree -d /etc/
 
# Include file sizes
tree -h /home/
 
# Exclude certain patterns
tree -I 'node_modules|.git' /home/projects/

Path Types

Absolute Paths

Start from the root directory (/).

# Absolute paths
/home/john/documents
/usr/bin/python3
/etc/passwd
 
# Navigate using absolute paths
cd /home/john/documents
cd /usr/bin
cd /var/log

Relative Paths

Relative to the current working directory.

# Current directory: /home/john
 
# Go to subdirectory
cd projects      # Actually: /home/john/projects
 
# Go to documents subdirectory
cd documents     # Actually: /home/john/documents
 
# Go to parent directory
cd ..            # Actually: /home
 
# Go to sibling directory
cd ../sarah      # Actually: /home/sarah
 
# Current directory reference
./script.sh      # Run script in current directory
cat ./file.txt   # Read file in current directory

Practical Filesystem Navigation

Finding Files and Directories

# Find files by name
find /home -name "*.txt" -type f
 
# Find large directories
du -sh /* | sort -rh | head -10
 
# Find recently modified files
find /home -type f -mtime -1  # Modified in last 24 hours
 
# Find files with specific permissions
find / -perm 777 -type f 2>/dev/null
 
# Search in specific location
locate filename  # Uses database (faster than find)
updatedb         # Update locate database

Viewing Directory Size

# Directory size
du -sh /home/
# 250G  /home/
 
# Size of each subdirectory
du -sh /home/*/ | sort -rh
 
# Show only directories
du -sh /var/*/ --exclude='*.*'
 
# Human-readable output with specific depth
du -sh --max-depth=1 /
 
# Find largest files
find / -type f -exec ls -lh {} \; | sort -k5 -rh | head -20

Best Practices

  1. Know the FHS Standard - Understanding directory purposes helps with system administration
  2. Keep /etc Organized - Back up important configuration files before making changes
  3. Monitor /var/log - Regularly check logs for system issues and security events
  4. Manage /tmp - Clean up temporary files to prevent disk space issues
  5. Use Absolute Paths in Scripts - Avoid issues with relative paths in automation
  6. Understand Mounting - Know which filesystems are mounted where for troubleshooting

Summary

The Linux filesystem hierarchy provides a standardized structure that ensures consistency across different systems. Key takeaways:

  • Root (/) is the starting point of all directories
  • System directories (/bin, /sbin, /etc) contain critical system files
  • User directories (/home, /root) contain user-specific data
  • Variable data (/var, /tmp) stores temporary and changing information
  • Temporary files can be safely cleared without affecting system operation
  • Navigation using absolute and relative paths is fundamental to Linux usage

Mastering the filesystem structure is essential for effective Linux administration and development.