You've logged into your Linux system, navigated directories, and managed filesβbut where is everything actually stored? Why is your user configuration in /home but system configuration in /etc? Why do programs live in /bin and /usr/bin? In this comprehensive guide, we'll explore the Linux filesystem hierarchy and understand the organized structure that makes Linux administration predictable and consistent across distributions.
π― What You'll Learn:
- Understanding the "everything is a file" philosophy
- The root directory (/) and why it's the starting point
- Complete overview of all major Linux directories
- FHS (Filesystem Hierarchy Standard) and why it matters
- What each directory contains and its purpose
- Where to find system files, user files, and temporary files
- Read-only vs writable directories
- Virtual filesystems (/proc, /sys, /dev)
- Best practices for navigating the filesystem
- 20+ comprehensive practice labs
Series: LFCS Certification - Phase 1 (Post 17 of 52) Prerequisites: Basic navigation commands (see Post 7)
The "Everything is a File" Philosophy
One of Linux's most fundamental concepts is that everything is a file. This isn't just a sayingβit's a design principle that makes the system remarkably consistent and powerful.
What Does "Everything is a File" Mean?
In Linux, whether you're accessing:
- A text document
- A directory
- A hard drive
- A network socket
- A running process
- Your keyboard or mouse
- A sound card
They're all represented as files!
Traditional thinking: "Directories, devices, and processes are different things"
Linux thinking: "If it can be read from or written to, it's a file"
This uniformity means the same tools and concepts work everywhere!
Why This Matters
Consistency: The same commands work on different types of files:
# Read a text file
cat myfile.txt
# Read a directory (list its contents)
cat /proc/cpuinfo
# Read hardware information (also a file!)
cat /sys/class/net/eth0/address
Simplicity: You don't need different tools for different resource types. Everything uses the same file operations: open, read, write, close.
Power: Standard file permissions work on everything. You can redirect output, pipe data, and use familiar tools everywhere.
The Root Directory: Where Everything Begins
Every file and directory in Linux starts from a single point: the root directory, represented by a forward slash /.
Understanding the Root Directory
Think of / as the trunk of a tree, with all other directories branching out from it:
/ (root)
|
+-------+-------+-------+-------+-------+-------+
| | | | | | |
bin etc home usr var tmp dev
| | | | | | |
(bins) (config)(users) (share) (logs) (temp) (devices)
All paths in Linux are absolute (starting from /) or relative (from current location)
Viewing the Root Directory
Let's explore what's actually in the root directory:
ls /
Typical output:
afs bin boot dev etc home lib lib64 media mnt opt
proc root run sbin srv sys tmp usr var
Let's get more details:
ls -l /
Example output:
dr-xr-xr-x. 2 root root 6 Jun 25 2024 afs
lrwxrwxrwx. 1 root root 7 Jun 25 2024 bin -> usr/bin
dr-xr-xr-x. 6 root root 4096 Oct 31 13:53 boot
drwxr-xr-x. 20 root root 3320 Nov 5 13:53 dev
drwxr-xr-x. 147 root root 8192 Nov 5 18:14 etc
drwxr-xr-x. 5 root root 54 Oct 28 15:06 home
lrwxrwxrwx. 1 root root 7 Jun 25 2024 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Jun 25 2024 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 Jun 25 2024 media
drwxr-xr-x. 2 root root 6 Jun 25 2024 mnt
drwxr-xr-x. 5 root root 41 Oct 28 15:13 opt
dr-xr-xr-x. 374 root root 0 Nov 5 13:53 proc
dr-xr-x---. 10 root root 4096 Nov 5 14:14 root
drwxr-xr-x. 44 root root 1260 Nov 5 18:14 run
lrwxrwxrwx. 1 root root 8 Jun 25 2024 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 Jun 25 2024 srv
dr-xr-xr-x. 13 root root 0 Nov 5 13:53 sys
drwxrwxrwt. 27 root root 4096 Nov 5 18:35 tmp
drwxr-xr-x. 12 root root 144 Jun 25 2024 usr
drwxr-xr-x. 20 root root 4096 Jun 25 2024 var
Notice several things:
- Directories start with
din permissions - Symbolic links start with
l(likebin -> usr/bin) - Most are owned by
root - Different permission patterns for different directories
FHS: The Filesystem Hierarchy Standard
The Filesystem Hierarchy Standard (FHS) is a reference standard maintained by the Linux Foundation that defines the directory structure and directory contents in Linux distributions.
Why FHS Matters
| Benefit | Example |
|---|---|
| Predictability | System configuration is always in /etc on any Linux distro |
| Portability | Scripts work across Ubuntu, CentOS, Debian, etc. |
| Documentation | When you read "edit /etc/fstab," you know exactly where to go |
| Software | Applications know where to install files |
| Troubleshooting | Logs are always in /var/log, never somewhere random |
β Key Point: FHS is why a system administrator who knows Ubuntu can immediately work on CentOS, and vice versa. The filesystem structure is standardized!
Complete Directory Overview
Let's explore every major directory in the Linux filesystem. We'll organize them by function.
System Binaries and Libraries
/bin - Essential User Binaries
Purpose: Contains essential command-line programs needed for basic system operation and repair.
Examples: ls, cp, mv, rm, cat, bash, pwd, mkdir
ls -l /bin
Key characteristics:
- Required for single-user mode
- Needed to bring the system up or repair it
- Available before
/usris mounted - On modern systems, often a symbolic link to
/usr/bin
/sbin - System Binaries
Purpose: Contains essential system administration programs.
Examples: fdisk, fsck, init, reboot, shutdown, ifconfig, iptables
ls -l /sbin
Key characteristics:
- Used primarily by the system administrator (root)
- Essential for booting, restoring, recovering
- Often symlinked to
/usr/sbinon modern systems
/lib and /lib64 - Shared Libraries
Purpose: Contains shared library files needed by programs in /bin and /sbin.
Think of it as: The Windows equivalent of DLL files
ls -l /lib /lib64
Key characteristics:
/lib: 32-bit libraries (on compatible systems)/lib64: 64-bit libraries- Contains kernel modules in
/lib/modules - Critical for system boot
Boot and Kernel Files
/boot - Boot Loader Files
Purpose: Contains everything needed to boot the operating system.
ls -l /boot
Common contents:
- vmlinuz: Compressed Linux kernel
- initramfs or initrd: Initial RAM disk for boot
- grub: Boot loader configuration
- System.map: Kernel symbol table
- config: Kernel configuration file
Example:
vmlinuz-5.14.0-626.el9.x86_64 # The kernel
initramfs-5.14.0-626.el9.x86_64.img # Initial RAM filesystem
grub2/ # GRUB bootloader config
β οΈ Warning: Never delete files from /boot unless you know exactly what you're doing! You could make your system unbootable.
Configuration and Data
/etc - System Configuration
Purpose: Contains all system-wide configuration files.
Name origin: Historically "et cetera" (and so on), though now considered "Editable Text Configuration"
ls /etc | head -20
Critical files in /etc:
| File/Directory | Purpose |
|---|---|
/etc/passwd | User account information |
/etc/shadow | Encrypted user passwords |
/etc/group | Group definitions |
/etc/hosts | Local hostname to IP mappings |
/etc/hostname | System hostname |
/etc/fstab | Filesystem mount table |
/etc/sudoers | sudo configuration |
/etc/ssh/ | SSH server configuration |
/etc/crontab | Scheduled jobs configuration |
/etc/systemd/ | systemd service configurations |
Key characteristic: /etc is typically text-based configuration files, making it easy to edit and backup.
/var - Variable Data
Purpose: Contains files that are expected to change frequently during normal system operation.
ls -l /var
Key subdirectories:
| Directory | Contains |
|---|---|
/var/log | System and application log files |
/var/cache | Application cache data |
/var/tmp | Temporary files (preserved across reboots) |
/var/spool | Print queues, mail queues, cron jobs |
/var/lib | Application state information |
/var/mail | User mailbox files |
Example - viewing recent log files:
ls -lht /var/log | head -10
User and Home Directories
/home - User Home Directories
Purpose: Contains a subdirectory for each regular user on the system.
ls -l /home
Example output:
drwx------. 25 centos9 centos9 4096 Nov 5 18:38 centos9
drwx------. 3 labuser labuser 78 Oct 28 15:13 labuser
drwx------. 2 labuser1 labuser1 62 Oct 28 15:13 labuser1
What's in a home directory:
- User documents and files
- Personal configuration files (dotfiles:
.bashrc,.vimrc, etc.) - Application data for that user
- Desktop, Downloads, Documents folders (on desktop systems)
ls -la ~
π‘ Shortcut: The ~ symbol always refers to your home directory, and ~username refers to another user's home directory.
/root - Root User's Home
Purpose: Home directory for the root user (system administrator).
Why separate from /home?
- Available early in boot process
- Not affected by /home mount issues
- Keeps root's files separate from users
sudo ls -la /root
Key difference from other homes:
- Located at
/root, not/home/root - Only accessible by root user by default
- Contains root's personal configs and scripts
Shared Resources
/usr - Unix System Resources
Purpose: Contains the majority of user utilities and applications.
This is a huge directory that we'll cover in detail in Post 18, but here's an overview:
ls -l /usr
Key subdirectories:
| Directory | Purpose |
|---|---|
/usr/bin | Most user commands and applications |
/usr/sbin | Non-essential system administration binaries |
/usr/lib | Libraries for binaries in /usr/bin and /usr/sbin |
/usr/share | Architecture-independent data (docs, icons, themes) |
/usr/local | Locally installed software (not from package manager) |
/usr/share/doc | Package documentation (we explored this in Post 14!) |
Key characteristic: /usr is typically read-only and shareable across systems.
Devices and Virtual Filesystems
/dev - Device Files
Purpose: Contains device files that represent hardware devices and virtual devices.
ls -l /dev | head -20
Common device files:
/dev/sda,/dev/sdb: Hard drives (SCSI/SATA)/dev/nvme0n1: NVMe SSD drives/dev/tty: Terminal devices/dev/null: The "black hole" - discards all data written to it/dev/zero: Provides infinite zeros/dev/random: Random number generator/dev/loop0: Loopback devices
Example - the null device:
# Redirect unwanted output to /dev/null (disappears!)
command-with-lots-of-output > /dev/null 2>&1
β
"Everything is a file" in action: Even hardware devices are accessed as files through /dev!
/proc - Process Information
Purpose: A virtual filesystem that provides a window into the kernel and running processes.
Key characteristic: Files don't actually exist on diskβthey're generated by the kernel on-the-fly!
ls /proc
Useful /proc files:
/proc/cpuinfo: CPU information/proc/meminfo: Memory information/proc/[PID]/: Directory for each running process/proc/version: Linux kernel version/proc/uptime: System uptime
Example:
# View CPU information
cat /proc/cpuinfo
# View memory information
cat /proc/meminfo
# View system uptime
cat /proc/uptime
/sys - System Information
Purpose: Another virtual filesystem that exposes kernel objects, hardware information, and device drivers.
ls /sys
Common uses:
- Hardware information
- Device driver parameters
- Kernel module information
Example:
# View network interface MAC address
cat /sys/class/net/eth0/address
Temporary and Runtime Files
/tmp - Temporary Files
Purpose: Directory for temporary files created by applications and users.
Key characteristics:
- Cleared on reboot (on most distributions)
- World-writable (anyone can create files)
- Uses the "sticky bit" for security (only owner can delete their files)
ls -ld /tmp
Output:
drwxrwxrwt. 27 root root 4096 Nov 5 18:35 /tmp
# ^
# ββ The 't' is the sticky bit
Example usage:
# Create a temporary file
touch /tmp/mytest.txt
# Anyone can write here
echo "test" > /tmp/test.txt
/run - Runtime Data
Purpose: Contains runtime data since last boot (replaces various locations used previously).
Contains:
- PID files
- Socket files
- Lock files
- Temporary runtime data
ls /run
Key characteristic: Cleared on reboot, similar to /tmp.
Mount Points and Optional Software
/media - Removable Media
Purpose: Mount point for removable media (USB drives, CD-ROMs, etc.).
ls /media
Modern usage: Often automounted under /media/username/device-name
/mnt - Temporary Mounts
Purpose: Temporary mount point for manually mounted filesystems.
Common usage:
# Mount a USB drive manually
sudo mount /dev/sdb1 /mnt
# Access the contents
ls /mnt
# Unmount when done
sudo umount /mnt
/opt - Optional Software
Purpose: Contains add-on application software packages.
Common usage: Third-party software often installs here instead of /usr
Examples:
/opt/google/chrome/
/opt/teamviewer/
/opt/vmware/
Service and Server Data
/srv - Service Data
Purpose: Contains data for services provided by the system.
Examples:
/srv/www/: Web server data/srv/ftp/: FTP server data/srv/git/: Git repositories
Note: Not all distributions/administrators use thisβsome prefer /var/www/ for web data.
Directory Classification
Let's organize directories by their characteristics:
Read-Only vs Writable
Read-Only (Mostly)
/usr- System resources/boot- Boot files/bin- Essential binaries/sbin- System binaries/lib- Shared libraries
Modified during system updates only
Writable
/home- User files/var- Variable data/tmp- Temporary files/etc- Configuration/root- Root's home
Frequently modified during normal use
Real vs Virtual Filesystems
Real Directories
/home- Actual files on disk/etc- Configuration files/var- Logs and data/usr- Programs and data/boot- Boot files
Take up disk space
Virtual Filesystems
/proc- Kernel/process info/sys- Device/driver info/dev- Device files/run- Runtime data
Generated on-the-fly, no disk space
Understanding man hier
Linux includes documentation about the filesystem hierarchy! The hier manual page describes all standard directories.
man hier
This manual page is an excellent reference for understanding each directory's purpose according to FHS standards.
Quick Reference Chart
| Directory | Purpose (One Line) | Example |
|---|---|---|
/ | Root - the starting point | cd / |
/bin | Essential user binaries | ls, cp, mv |
/boot | Boot loader and kernel files | vmlinuz, grub |
/dev | Device files | /dev/sda, /dev/null |
/etc | System configuration | /etc/passwd, /etc/hosts |
/home | User home directories | /home/username |
/lib | Essential shared libraries | libc.so.6 |
/media | Removable media mount points | USB drives, CD-ROMs |
/mnt | Temporary mount point | Manual mounts |
/opt | Optional add-on software | Third-party apps |
/proc | Virtual: process/kernel info | /proc/cpuinfo |
/root | Root user's home | Root's files |
/run | Runtime data since boot | PID files, sockets |
/sbin | System administration binaries | fdisk, reboot |
/srv | Service data | Web/FTP server files |
/sys | Virtual: hardware/driver info | /sys/class/net |
/tmp | Temporary files (cleared on boot) | Temp working files |
/usr | Unix system resources | Programs, libraries, docs |
/var | Variable data (logs, caches) | /var/log |
π§ͺ Practice Labs
Time to explore the filesystem hands-on! These 20 labs will help you understand where everything lives in Linux.
Warm-Up Labs (Beginner)
Lab 1: Explore the Root Directory (Beginner)
Task: List the contents of the root directory and understand what you're seeing.
Steps:
- Navigate to the root directory
- List its contents
- Count how many top-level directories exist
- Identify which items are symbolic links
Show Solution
Solution:
# Navigate to root
cd /
# List contents
ls
# List with details to see symlinks and permissions
ls -l
# Count directories (lines with 'd' at start)
ls -l / | grep '^d' | wc -l
# See symlinks (lines with 'l' at start)
ls -l / | grep '^l'
# Example symlinks you'll see:
# bin -> usr/bin
# lib -> usr/lib
# lib64 -> usr/lib64
What you'll learn: The root directory is organized and many directories are actually symlinks to locations in /usr.
Expected output: Around 20 top-level directories, several being symlinks.
Lab 2: Find Your Home Directory (Beginner)
Task: Explore different ways to navigate to and reference your home directory.
Steps:
- Use
~to go to home - Use
$HOMEvariable - Use
cdwith no arguments - Verify they all lead to the same place
Show Solution
Solution:
# Method 1: Tilde
cd ~
pwd
# Output: /home/username
# Method 2: HOME variable
cd $HOME
pwd
# Output: /home/username
# Method 3: cd alone
cd
pwd
# Output: /home/username
# Verify they're the same
echo "Home via tilde: ~"
echo "Home via variable: $HOME"
echo "Current location: $(pwd)"
# All three should show /home/youruser
What you'll learn: Multiple ways to reference your home directory in Linux.
Pro tip: ~ is the most commonly used shortcut in practice.
Lab 3: Explore /etc Configuration Files (Beginner)
Task: Discover what types of configuration files live in /etc.
Steps:
- Navigate to
/etc - List the contents
- Find the hostname file
- Find the hosts file
- Count how many items are in
/etc
Show Solution
Solution:
# Navigate to /etc
cd /etc
# List contents
ls
# Find specific files
ls -l hostname
ls -l hosts
# View hostname
cat hostname
# View hosts file (first 10 lines)
head hosts
# Count items in /etc
ls | wc -l
# Count directories vs files
ls -l | grep '^d' | wc -l # Directories
ls -l | grep '^-' | wc -l # Files
What you'll learn: /etc contains hundreds of configuration files and subdirectories for system-wide settings.
Expected: 100+ items in /etc, mix of files and directories.
Lab 4: Explore Virtual Filesystems (Beginner)
Task: Understand that /proc and /sys are virtualβthey don't actually exist on disk.
Steps:
- View your CPU information from
/proc - Check memory info from
/proc - View system uptime
- Understand these files are generated on-the-fly
Show Solution
Solution:
# View CPU information
cat /proc/cpuinfo
# View memory information
cat /proc/meminfo
# View system uptime
cat /proc/uptime
# Output: two numbers (uptime in seconds, idle time)
# Calculate uptime in hours
echo "scale=2; $(cat /proc/uptime | awk '{print $1}') / 3600" | bc
# Check kernel version
cat /proc/version
# List all processes (each numbered directory is a PID)
ls /proc | grep '^[0-9]' | head -10
What you'll learn: /proc provides real-time system and process information generated by the kernel.
Mind-blowing fact: These "files" don't use any disk spaceβthey're created in memory!
Lab 5: Test the /dev/null Black Hole (Beginner)
Task: Experiment with /dev/null to understand how it discards data.
Steps:
- Write some text to
/dev/null - Try to read from
/dev/null - Redirect command output to
/dev/null - Understand when this is useful
Show Solution
Solution:
# Write to /dev/null (data disappears!)
echo "This text vanishes" > /dev/null
# Try to read it back (nothing there!)
cat /dev/null
# (No output)
# Redirect unwanted output
ls /root 2> /dev/null
# Errors disappear instead of showing on screen
# Silence both stdout and stderr
some-noisy-command > /dev/null 2>&1
# Check that /dev/null is a character device
ls -l /dev/null
# crw-rw-rw-. 1 root root 1, 3 ...
What you'll learn: /dev/null is the "black hole" for unwanted output.
Use case: Silencing errors or output you don't need to see.
Core Practice Labs (Intermediate)
Lab 6: Navigate the /var Directory Structure (Intermediate)
Task: Explore /var and understand what "variable data" means.
Steps:
- Navigate to
/var - Identify the subdirectories
- Explore
/var/log - Find the largest log file
- View recent system logs
Show Solution
Solution:
# Navigate to /var
cd /var
# List subdirectories
ls -l
# Navigate to logs
cd log
# List log files by size
ls -lhS
# Find largest log file
du -h * | sort -rh | head -5
# View system messages (may need sudo)
sudo tail /var/log/messages
# or on Ubuntu/Debian:
sudo tail /var/log/syslog
# Check auth logs
sudo tail /var/log/secure
# or on Ubuntu/Debian:
sudo tail /var/log/auth.log
What you'll learn: /var contains frequently changing data like logs, caches, and spools.
Real-world: Troubleshooting always starts with checking /var/log.
Lab 7: Understand /usr Structure (Intermediate)
Task: Explore the /usr hierarchy and understand it's the largest directory.
Steps:
- Navigate to
/usr - List subdirectories
- Explore
/usr/binand/usr/share - Find documentation in
/usr/share/doc - Check disk usage of
/usr
Show Solution
Solution:
# Navigate to /usr
cd /usr
# List main subdirectories
ls -l
# Count commands in /usr/bin
ls /usr/bin | wc -l
# Likely 1000+ commands!
# Explore shared data
ls /usr/share
# Find documentation (we covered this in Post 14!)
ls /usr/share/doc | head -20
# Check disk usage of /usr
du -sh /usr
# Compare sizes of major directories
du -sh /usr/*
# Find where 'ls' command lives
which ls
# Output: /usr/bin/ls (or /bin/ls which links to /usr/bin/ls)
What you'll learn: /usr is massive and contains most of your installed software.
Interesting: /usr often takes up several gigabytes of space.
Lab 8: Test Write Permissions Across Directories (Intermediate)
Task: Discover which directories you can write to as a regular user.
Steps:
- Try to create a file in
/(will fail) - Try in
/etc(will fail) - Try in
/tmp(will succeed) - Try in your home directory (will succeed)
- Understand permission patterns
Show Solution
Solution:
# Try to write to root directory (fails)
touch /testfile
# Error: Permission denied
# Try to write to /etc (fails)
touch /etc/testfile
# Error: Permission denied
# Try to write to /var/log (fails)
touch /var/log/testfile
# Error: Permission denied
# Try to write to /tmp (succeeds!)
touch /tmp/testfile
ls -l /tmp/testfile
# Works! Anyone can write to /tmp
# Try in home directory (succeeds)
touch ~/testfile
ls -l ~/testfile
# Works! You own your home directory
# Clean up
rm /tmp/testfile ~/testfile
What you'll learn: Regular users can only write to /tmp and their home directory (and a few other specific locations).
Why this matters: Understanding write permissions prevents "permission denied" frustration.
Lab 9: Explore Process Directories in /proc (Intermediate)
Task: Understand that each running process has a directory in /proc.
Steps:
- Find your shell's process ID (PID)
- Explore your shell's
/proc/[PID]directory - View process command line
- View process environment variables
- See process status
Show Solution
Solution:
# Find current shell PID
echo $$
# Store it in a variable for easy use
MY_PID=$$
# Navigate to your process directory
cd /proc/$MY_PID
# List contents
ls -l
# View command line that started this process
cat cmdline
echo # Add newline for readability
# View environment variables
cat environ | tr '\0' '\n' | head -20
# View process status
cat status | head -20
# View current working directory (symlink)
ls -l cwd
# View executable (symlink)
ls -l exe
What you'll learn: Every running process is represented as a directory in /proc.
Mind-blowing: You can explore running processes as if they were files!
Lab 10: Investigate Boot Directory (Intermediate)
Task: Explore /boot and understand what makes your system bootable.
Steps:
- List contents of
/boot - Identify the kernel file
- Find the initramfs
- Explore GRUB configuration
- Never delete anything!
Show Solution
Solution:
# List boot directory
ls -lh /boot
# Find kernel (vmlinuz file)
ls -lh /boot/vmlinuz*
# Find initramfs (initial RAM filesystem)
ls -lh /boot/initramfs*
# Check GRUB configuration
ls -l /boot/grub2/
# View GRUB config (don't edit!)
sudo cat /boot/grub2/grub.cfg | head -50
# Check disk space used by /boot
du -sh /boot
# See all installed kernels
ls /boot/vmlinuz* | wc -l
What you'll learn: /boot contains the kernel and files needed to start Linux.
WARNING: NEVER delete files from /boot unless you know exactly what you're doing!
Lab 11: Explore Device Files in /dev (Intermediate)
Task: Understand how hardware devices are represented as files.
Steps:
- List block devices (storage)
- List character devices
- Find your hard drive device file
- Explore terminal devices
- Test
/dev/zero
Show Solution
Solution:
# List block devices (storage)
ls -l /dev | grep '^b' | head -10
# Look for sda, sdb (SCSI/SATA drives)
# or nvme0n1 (NVMe drives)
# List character devices
ls -l /dev | grep '^c' | head -10
# Find your main hard drive
ls -l /dev/sda* 2>/dev/null || ls -l /dev/nvme0n1* 2>/dev/null
# List terminal devices
ls -l /dev/tty*
# See current terminal
tty
# Test /dev/zero (provides infinite zeros)
dd if=/dev/zero bs=1M count=10 | wc -c
# Output: 10485760 (10MB of zeros)
# Test /dev/random (random data)
head -c 16 /dev/random | base64
# Generates 16 random bytes, encoded in base64
What you'll learn: Hardware devices are accessed as special files in /dev.
Cool fact: You can read/write to devices just like regular files!
Lab 12: Compare /tmp vs /var/tmp (Intermediate)
Task: Understand the difference between /tmp and /var/tmp.
Steps:
- Check permissions on both
- Create test files in both
- Understand cleanup policies
- Check disk usage
Show Solution
Solution:
# Check permissions
ls -ld /tmp
ls -ld /var/tmp
# Both should show the sticky bit (t)
# Create test files
echo "temp file" > /tmp/test.txt
echo "var temp file" > /var/tmp/test.txt
# Check them
ls -l /tmp/test.txt
ls -l /var/tmp/test.txt
# Check disk usage
du -sh /tmp
du -sh /var/tmp
# Key difference: /tmp is cleared on reboot
# /var/tmp persists across reboots (but may be cleaned periodically)
# Verify sticky bit prevents deletion by other users
ls -ld /tmp | grep 't$'
# Clean up
rm /tmp/test.txt /var/tmp/test.txt
What you'll learn: Both are for temporary files, but /var/tmp persists across reboots.
Use case: Use /tmp for session data, /var/tmp for data that should survive reboot.
Lab 13: Find Symbolic Links in Root (Intermediate)
Task: Identify which top-level directories are actually symbolic links.
Steps:
- List root directory showing file types
- Identify all symbolic links
- See where they point
- Understand why these links exist
Show Solution
Solution:
# List root with file type indicators
ls -l / | grep '^l'
# Common symlinks you'll find:
# bin -> usr/bin
# lib -> usr/lib
# lib64 -> usr/lib64
# sbin -> usr/sbin
# Verify with readlink
readlink /bin
# Output: usr/bin
readlink /lib
# Output: usr/lib
# See all symlinks in root
find / -maxdepth 1 -type l -ls
# Understand why: modern Linux consolidates binaries in /usr
# but keeps /bin, /lib, /sbin as compatibility symlinks
What you'll learn: Modern Linux has consolidated many directories into /usr, using symlinks for compatibility.
Historical: Older systems had separate /bin and /usr/bin; now they're unified.
Challenge Labs (Advanced)
Lab 14: Calculate Directory Sizes (Advanced)
Task: Find the largest directories on your system and understand disk usage.
Steps:
- Check total disk usage
- Find the 10 largest directories in root
- Identify what's using the most space
- Understand which directories can grow
Show Solution
Solution:
# Check overall disk usage
df -h
# Find 10 largest directories in root (may take a while)
sudo du -h --max-depth=1 / 2>/dev/null | sort -rh | head -10
# Example output interpretation:
# /usr is usually largest (programs)
# /var grows over time (logs)
# /home depends on user data
# Check specific important directories
du -sh /usr /var /home /opt 2>/dev/null
# Find largest subdirectories in /var
sudo du -h --max-depth=1 /var | sort -rh | head -10
# Find large files in /var/log
sudo find /var/log -type f -size +100M -exec ls -lh {} \;
# Clean old logs if needed (be careful!)
# sudo journalctl --vacuum-time=7d
What you'll learn: /usr, /var, and /home typically use the most disk space.
Real-world: Monitoring disk usage prevents system crashes from full disks.
Lab 15: Create a Filesystem Map (Advanced)
Task: Document the entire filesystem structure by creating a visual tree.
Steps:
- Use the
treecommand (install if needed) - Create a filesystem map showing key directories
- Save it for reference
- Understand the hierarchy visually
Show Solution
Solution:
# Install tree if not available
# Ubuntu/Debian:
sudo apt install tree
# CentOS/RHEL:
sudo dnf install tree
# Show root directory tree (1 level deep)
tree -L 1 -d /
# Show /etc tree (2 levels)
tree -L 2 -d /etc | head -50
# Show /var tree
tree -L 2 -d /var
# Create a full filesystem map (1 level)
tree -L 1 -d / > ~/filesystem-map.txt
# View it
cat ~/filesystem-map.txt
# Create detailed map with descriptions
cat > ~/filesystem-guide.txt << 'EOF'
Linux Filesystem Hierarchy
============================
/ Root directory (starting point)
βββ bin Essential user binaries (ls, cp, mv)
βββ boot Boot loader and kernel files
βββ dev Device files
βββ etc System configuration
βββ home User home directories
βββ lib Shared libraries
βββ media Removable media mount points
βββ mnt Temporary mounts
βββ opt Optional add-on software
βββ proc Virtual: process/kernel info
βββ root Root user's home
βββ run Runtime data
βββ sbin System administration binaries
βββ srv Service data
βββ sys Virtual: hardware/driver info
βββ tmp Temporary files (cleared on boot)
βββ usr Unix system resources (programs, docs)
βββ var Variable data (logs, caches)
EOF
cat ~/filesystem-guide.txt
What you'll learn: Visualizing the hierarchy helps internalize the structure.
Pro tip: Keep this reference handy for quick lookups!
Lab 16: Explore Hidden Files and Dotfiles (Advanced)
Task: Understand hidden files (dotfiles) and their locations.
Steps:
- List hidden files in your home directory
- Understand common dotfiles
- Find system-wide configuration dotfiles
- View a
.bashrcfile
Show Solution
Solution:
# List all files including hidden
ls -la ~
# List ONLY hidden files
ls -lda ~/.*
# Common dotfiles you'll see:
# .bashrc - Bash configuration
# .bash_profile - Bash login configuration
# .bash_history - Command history
# .ssh/ - SSH keys and configuration
# .vimrc - Vim editor configuration
# View your .bashrc
cat ~/.bashrc
# Count hidden files
ls -la ~ | grep '^\.' | wc -l
# Find all dotfiles system-wide (sample)
find /etc -maxdepth 1 -name ".*" 2>/dev/null
# View .bash_history (your command history!)
tail ~/.bash_history
What you'll learn: Hidden files (starting with .) contain user and application configurations.
Tip: Dotfiles are how you customize your Linux experience!
Lab 17: Investigate Mounted Filesystems (Advanced)
Task: Understand what filesystems are mounted and where.
Steps:
- View all mounted filesystems
- Check the mount points
- Understand filesystem types
- View mount options
Show Solution
Solution:
# Show all mounted filesystems
mount
# More readable version
mount | column -t
# Show just the mount points
df -h
# View /proc/mounts (kernel's view)
cat /proc/mounts
# View /etc/fstab (permanent mount configuration)
cat /etc/fstab
# Show filesystem types
df -T
# Find virtual filesystems
mount | grep -E 'proc|sys|dev'
# Example output interpretation:
# tmpfs - temporary filesystem in RAM
# proc - virtual process filesystem
# sysfs - virtual system/device filesystem
# ext4/xfs - real disk filesystems
What you'll learn: Linux mounts various filesystem types, both real and virtual.
Important: Understanding mounts is crucial for disk management.
Lab 18: Read Kernel Information from /proc (Advanced)
Task: Extract detailed system information from /proc.
Steps:
- Get CPU information
- Get memory information
- Get kernel version
- Get loaded modules
- Create a system info report
Show Solution
Solution:
# CPU information
cat /proc/cpuinfo | grep -E 'model name|cpu cores|siblings' | head -10
# Memory information
cat /proc/meminfo | grep -E 'MemTotal|MemFree|MemAvailable'
# Kernel version
cat /proc/version
# Or simpler:
uname -r
# System uptime
cat /proc/uptime
# First number is uptime in seconds
# Uptime in human format
uptime
# Loaded kernel modules
lsmod
# Or from proc:
cat /proc/modules | head -10
# Create system info report
cat > ~/system-info.txt << EOF
System Information Report
=========================
Generated: $(date)
Kernel: $(uname -r)
Hostname: $(hostname)
Uptime: $(uptime -p)
CPU: $(grep 'model name' /proc/cpuinfo | head -1 | cut -d: -f2)
CPU Cores: $(grep -c processor /proc/cpuinfo)
Memory Total: $(grep MemTotal /proc/meminfo | awk '{print $2/1024 " MB"}')
Memory Free: $(grep MemFree /proc/meminfo | awk '{print $2/1024 " MB"}')
Disk Usage:
$(df -h / | tail -1)
EOF
cat ~/system-info.txt
What you'll learn: /proc is a goldmine of system information.
Real-world: System monitoring tools read from /proc to gather metrics.
Lab 19: Understand File Types Across Directories (Advanced)
Task: Learn to identify different file types using ls -l output.
Steps:
- Find examples of each file type
- Regular files (-)
- Directories (d)
- Symbolic links (l)
- Character devices (c)
- Block devices (b)
Show Solution
Solution:
# Regular file
ls -l ~/.bashrc
# Output starts with: -
# Directory
ls -ld /etc
# Output starts with: d
# Symbolic link
ls -l /bin
# Output starts with: l
# Shows: bin -> usr/bin
# Character device
ls -l /dev/null
# Output starts with: c
# Block device
ls -l /dev/sda 2>/dev/null || ls -l /dev/nvme0n1 2>/dev/null
# Output starts with: b
# Find examples of each type
echo "=== Regular Files ==="
find /etc -maxdepth 1 -type f 2>/dev/null | head -5
echo "=== Directories ==="
find /etc -maxdepth 1 -type d 2>/dev/null | head -5
echo "=== Symbolic Links ==="
find /etc -maxdepth 1 -type l 2>/dev/null | head -5
echo "=== Character Devices ==="
find /dev -maxdepth 1 -type c 2>/dev/null | head -5
echo "=== Block Devices ==="
find /dev -maxdepth 1 -type b 2>/dev/null | head -5
# Create a file type reference
cat > ~/file-types.txt << 'EOF'
File Types in Linux (first character in ls -l):
================================================
- Regular file
d Directory
l Symbolic link
c Character device (keyboard, mouse, terminal)
b Block device (hard drives, USB drives)
p Named pipe (FIFO)
s Socket
EOF
cat ~/file-types.txt
What you'll learn: Linux has several file types beyond just "files" and "directories".
Key skill: Quickly identifying file types from ls -l output.
Lab 20: Create a Complete Filesystem Cheat Sheet (Advanced)
Task: Build a comprehensive reference guide for the Linux filesystem.
Steps:
- Create a detailed cheat sheet
- Include all major directories
- Add examples and use cases
- Save it for future reference
Show Solution
Solution:
# Create comprehensive filesystem cheat sheet
cat > ~/linux-filesystem-cheatsheet.txt << 'EOF'
====================================================
LINUX FILESYSTEM HIERARCHY - COMPLETE CHEAT SHEET
====================================================
ROOT DIRECTORY
/ Root - Starting point of filesystem tree
ESSENTIAL BINARIES
/bin Essential user binaries (ls, cp, mv, bash)
/sbin System administration binaries (fdisk, reboot)
/lib, /lib64 Shared libraries needed by /bin and /sbin
BOOT FILES
/boot Boot loader, kernel, initramfs
DEVICES
/dev Device files (sda, tty, null, zero, random)
CONFIGURATION
/etc System-wide configuration files
Examples: /etc/passwd, /etc/hosts, /etc/fstab
USER DATA
/home User home directories (/home/username)
/root Root user's home directory
SYSTEM RESOURCES
/usr Unix System Resources (most programs live here)
/usr/bin User commands and applications
/usr/sbin Non-essential system binaries
/usr/lib Libraries for /usr/bin and /usr/sbin
/usr/share Architecture-independent data (docs, icons)
/usr/local Locally installed software
VARIABLE DATA
/var Variable data (changes frequently)
/var/log Log files (CRITICAL for troubleshooting)
/var/cache Application cache
/var/tmp Temp files (preserved across reboots)
/var/spool Print queues, mail queues, cron jobs
VIRTUAL FILESYSTEMS (Generated by kernel, not on disk)
/proc Process and kernel information
/sys Hardware and device information
/dev Device files
TEMPORARY FILES
/tmp Temporary files (cleared on reboot)
/run Runtime data since last boot
MOUNT POINTS
/media Removable media (USB, CD-ROM)
/mnt Temporary manual mounts
OPTIONAL/SERVICE
/opt Optional add-on software packages
/srv Service data (web, ftp servers)
QUICK TIPS
----------
- Use 'man hier' for official documentation
- Use 'df -h' to see disk usage by filesystem
- Use 'du -sh *' to see directory sizes
- Regular users can write to: /tmp, /home/username, /var/tmp
- Virtual filesystems (/proc, /sys, /dev) use no disk space
- Logs are always in /var/log
- Configuration is always in /etc
- User files go in /home/username
COMMON TASKS
------------
View logs: tail /var/log/messages
Check disk: df -h
Check directory size: du -sh /path
Find a file: find / -name filename
List all devices: ls /dev
View CPU info: cat /proc/cpuinfo
View memory: cat /proc/meminfo
View kernel: cat /proc/version
FHS COMPLIANCE
--------------
Most Linux distributions follow the Filesystem Hierarchy
Standard (FHS), ensuring consistency across systems.
====================================================
EOF
cat ~/linux-filesystem-cheatsheet.txt
# Make it easy to find
echo "Cheat sheet saved to: ~/linux-filesystem-cheatsheet.txt"
echo "View anytime with: cat ~/linux-filesystem-cheatsheet.txt"
What you'll learn: Creating your own reference materials helps internalize the knowledge.
Pro tip: Keep this cheat sheet handy during your LFCS studies and real-world work!
π Best Practices
For System Navigation
-
Learn the shortcuts
cd ~ # Go home cd - # Go to previous directory cd .. # Go up one level cd / # Go to root -
Use tab completion
- Type
cd /uand press Tab - Linux completes to
cd /usr/
- Type
-
Bookmark common locations
alias logs='cd /var/log' alias docs='cd /usr/share/doc'
For Understanding Locations
-
"When in doubt, check man hier"
man hier -
Logs are always in /var/log
- Troubleshooting? Start here
-
Configuration is always in /etc
- Need to configure something? Look in /etc
-
User files go in /home
- Never store personal files in system directories
For Safety
-
Never delete from /boot, /bin, /sbin, /lib
- You can break your system!
-
Be careful with root-owned directories
- Use sudo only when necessary
- Double-check before running destructive commands
-
Use /tmp for temporary work
- It's designed for that purpose
- Cleaned automatically
π¨ Common Pitfalls to Avoid
Pitfall 1: Confusing / and ~
Problem: Thinking / (root) and ~ (home) are the same.
# β Wrong: Not the same!
cd / # Goes to root directory
cd ~ # Goes to YOUR home directory
# β
Right: Understand the difference
cd / # System root
pwd # Output: /
cd ~ # Your home
pwd # Output: /home/username
Pitfall 2: Trying to Write to Read-Only Directories
Problem: Attempting to create files in system directories.
# β Wrong: Will fail
touch /new-file
# Error: Permission denied
# β
Right: Use appropriate locations
touch ~/new-file # Your home
touch /tmp/new-file # Temporary
Pitfall 3: Forgetting Virtual Filesystems Don't Use Disk
Problem: Worrying about disk space used by /proc or /sys.
# β Wrong interpretation:
df -h /proc
# Shows usage, but it's all virtual (no real disk space)
# β
Right understanding:
# /proc, /sys, /dev are virtual
# They don't actually consume disk space
Pitfall 4: Not Understanding Symbolic Links
Problem: Confused when /bin and /usr/bin have the same content.
# β Confusion:
ls /bin
ls /usr/bin
# "Why are these the same?!"
# β
Understanding:
readlink /bin
# Output: usr/bin
# They're the SAME location via symlink!
Pitfall 5: Deleting Important System Files
Problem: Accidentally deleting critical files.
# β VERY WRONG: Never do this!
sudo rm -rf /boot/*
sudo rm -rf /etc/*
# β
Right: Be extremely careful with sudo rm
# Always double-check the path
# Use -i for interactive confirmation
sudo rm -i /etc/some-config-file
π Command Cheat Sheet
Navigation
cd / # Go to root
cd ~ # Go to home
cd - # Go to previous directory
pwd # Print working directory
ls -l / # List root directory
tree -L 1 / # Tree view of root (1 level)
Exploring Directories
ls -l /etc # List configuration files
ls -l /var/log # List log files
ls -l /usr/bin # List user commands
du -sh /var/* # Directory sizes in /var
df -h # Disk usage by filesystem
Virtual Filesystems
cat /proc/cpuinfo # CPU information
cat /proc/meminfo # Memory information
cat /proc/version # Kernel version
ls /proc # Process list (PIDs)
cat /sys/class/net/*/address # Network MAC addresses
Device Files
ls -l /dev/sd* # SCSI/SATA drives
ls -l /dev/tty* # Terminals
cat /dev/null # The black hole
head -c 10 /dev/zero # Get zeros
head -c 10 /dev/random # Get random data
System Information
man hier # Filesystem hierarchy documentation
df -h # Disk usage
mount # Show mounted filesystems
lsblk # List block devices
findmnt # Show mount points in tree format
π― Key Takeaways
Essential Concepts
- β Everything is a file: Devices, processes, and data are all accessed as files
- β Root directory /: The starting point of the entire filesystem tree
- β FHS compliance: Standard hierarchy makes Linux predictable across distributions
- β /etc: All system configuration lives here
- β /var/log: Logs are critical for troubleshooting
- β /home: User files and personal configuration
- β /usr: Where most programs and documentation live
- β Virtual filesystems: /proc, /sys, /dev are generated by kernel
- β /tmp: Safe place for temporary files (cleared on reboot)
- β Symbolic links: /bin, /lib, /sbin often link to /usr equivalents
π What's Next?
Excellent work! You've mastered the Linux filesystem hierarchy and understand where everything lives. You now know:
- β The "everything is a file" philosophy
- β The purpose of every major directory
- β Real vs virtual filesystems
- β Where to find logs, configs, programs, and data
- β Safe locations for creating files
In the next post (Part 18), we'll dive deep into the /usr directoryβexploring /usr/bin, /usr/lib, /usr/share, /usr/local, and understanding why most of your installed software lives here. We'll cover the distinction between /usr/bin and /usr/local/bin, and best practices for software installation.
Coming up in this series:
- Post 18: Understanding /usr Directory Deep Dive
- Post 19: Understanding /var and /etc Explained
- Post 20: Write Permissions and Access Control
π Congratulations! You've completed LFCS Phase 1 Part 17! You now understand the Linux filesystem hierarchy like a professional system administrator. This knowledge forms the foundation for everything else you'll do in Linux.
Practice suggestion: Navigate through each major directory we discussed. Read files in /proc, explore configs in /etc, check logs in /var/log, and get comfortable with the structure. The more you explore, the more natural it becomes!
Series Navigation:
- β Previous: Part 16 - Managing Hostnames with hostname and hostnamectl
- β Next: Part 18 - Understanding /usr Directory Deep Dive (Coming Soon)
Part of the LFCS Certification Preparation Series - Phase 1 of 9

