LFCS Phase 1 Part 17: Understanding Linux Filesystem Hierarchy Part 1 - Overview

Master the Linux filesystem hierarchy and understand where everything lives. Learn the FHS standard, explore all major directories from /bin to /var, and discover the 'everything is a file' philosophy for LFCS certification.

41 min read

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!

The File Philosophy

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:

Linux Filesystem Tree
                    / (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 d in permissions
  • Symbolic links start with l (like bin -> 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

BenefitExample
PredictabilitySystem configuration is always in /etc on any Linux distro
PortabilityScripts work across Ubuntu, CentOS, Debian, etc.
DocumentationWhen you read "edit /etc/fstab," you know exactly where to go
SoftwareApplications know where to install files
TroubleshootingLogs 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 /usr is 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/sbin on 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/DirectoryPurpose
/etc/passwdUser account information
/etc/shadowEncrypted user passwords
/etc/groupGroup definitions
/etc/hostsLocal hostname to IP mappings
/etc/hostnameSystem hostname
/etc/fstabFilesystem mount table
/etc/sudoerssudo configuration
/etc/ssh/SSH server configuration
/etc/crontabScheduled 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:

DirectoryContains
/var/logSystem and application log files
/var/cacheApplication cache data
/var/tmpTemporary files (preserved across reboots)
/var/spoolPrint queues, mail queues, cron jobs
/var/libApplication state information
/var/mailUser 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:

DirectoryPurpose
/usr/binMost user commands and applications
/usr/sbinNon-essential system administration binaries
/usr/libLibraries for binaries in /usr/bin and /usr/sbin
/usr/shareArchitecture-independent data (docs, icons, themes)
/usr/localLocally installed software (not from package manager)
/usr/share/docPackage 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

DirectoryPurpose (One Line)Example
/Root - the starting pointcd /
/binEssential user binariesls, cp, mv
/bootBoot loader and kernel filesvmlinuz, grub
/devDevice files/dev/sda, /dev/null
/etcSystem configuration/etc/passwd, /etc/hosts
/homeUser home directories/home/username
/libEssential shared librarieslibc.so.6
/mediaRemovable media mount pointsUSB drives, CD-ROMs
/mntTemporary mount pointManual mounts
/optOptional add-on softwareThird-party apps
/procVirtual: process/kernel info/proc/cpuinfo
/rootRoot user's homeRoot's files
/runRuntime data since bootPID files, sockets
/sbinSystem administration binariesfdisk, reboot
/srvService dataWeb/FTP server files
/sysVirtual: hardware/driver info/sys/class/net
/tmpTemporary files (cleared on boot)Temp working files
/usrUnix system resourcesPrograms, libraries, docs
/varVariable 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:

  1. Navigate to the root directory
  2. List its contents
  3. Count how many top-level directories exist
  4. 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:

  1. Use ~ to go to home
  2. Use $HOME variable
  3. Use cd with no arguments
  4. 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:

  1. Navigate to /etc
  2. List the contents
  3. Find the hostname file
  4. Find the hosts file
  5. 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:

  1. View your CPU information from /proc
  2. Check memory info from /proc
  3. View system uptime
  4. 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:

  1. Write some text to /dev/null
  2. Try to read from /dev/null
  3. Redirect command output to /dev/null
  4. 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:

  1. Navigate to /var
  2. Identify the subdirectories
  3. Explore /var/log
  4. Find the largest log file
  5. 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:

  1. Navigate to /usr
  2. List subdirectories
  3. Explore /usr/bin and /usr/share
  4. Find documentation in /usr/share/doc
  5. 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:

  1. Try to create a file in / (will fail)
  2. Try in /etc (will fail)
  3. Try in /tmp (will succeed)
  4. Try in your home directory (will succeed)
  5. 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:

  1. Find your shell's process ID (PID)
  2. Explore your shell's /proc/[PID] directory
  3. View process command line
  4. View process environment variables
  5. 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:

  1. List contents of /boot
  2. Identify the kernel file
  3. Find the initramfs
  4. Explore GRUB configuration
  5. 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:

  1. List block devices (storage)
  2. List character devices
  3. Find your hard drive device file
  4. Explore terminal devices
  5. 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:

  1. Check permissions on both
  2. Create test files in both
  3. Understand cleanup policies
  4. 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.

Task: Identify which top-level directories are actually symbolic links.

Steps:

  1. List root directory showing file types
  2. Identify all symbolic links
  3. See where they point
  4. 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:

  1. Check total disk usage
  2. Find the 10 largest directories in root
  3. Identify what's using the most space
  4. 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:

  1. Use the tree command (install if needed)
  2. Create a filesystem map showing key directories
  3. Save it for reference
  4. 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:

  1. List hidden files in your home directory
  2. Understand common dotfiles
  3. Find system-wide configuration dotfiles
  4. View a .bashrc file
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:

  1. View all mounted filesystems
  2. Check the mount points
  3. Understand filesystem types
  4. 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:

  1. Get CPU information
  2. Get memory information
  3. Get kernel version
  4. Get loaded modules
  5. 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:

  1. Find examples of each file type
  2. Regular files (-)
  3. Directories (d)
  4. Symbolic links (l)
  5. Character devices (c)
  6. 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:

  1. Create a detailed cheat sheet
  2. Include all major directories
  3. Add examples and use cases
  4. 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

  1. Learn the shortcuts

    cd ~      # Go home
    cd -      # Go to previous directory
    cd ..     # Go up one level
    cd /      # Go to root
    
  2. Use tab completion

    • Type cd /u and press Tab
    • Linux completes to cd /usr/
  3. Bookmark common locations

    alias logs='cd /var/log'
    alias docs='cd /usr/share/doc'
    

For Understanding Locations

  1. "When in doubt, check man hier"

    man hier
    
  2. Logs are always in /var/log

    • Troubleshooting? Start here
  3. Configuration is always in /etc

    • Need to configure something? Look in /etc
  4. User files go in /home

    • Never store personal files in system directories

For Safety

  1. Never delete from /boot, /bin, /sbin, /lib

    • You can break your system!
  2. Be careful with root-owned directories

    • Use sudo only when necessary
    • Double-check before running destructive commands
  3. 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

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

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:

Part of the LFCS Certification Preparation Series - Phase 1 of 9

Owais

Written by Owais

I'm an AIOps Engineer with a passion for AI, Operating Systems, Cloud, and Securityβ€”sharing insights that matter in today's tech world.

I completed the UK's Eduqual Level 6 Diploma in AIOps from Al Nafi International College, a globally recognized program that's changing careers worldwide. This diploma is:

  • βœ… Available online in 17+ languages
  • βœ… Includes free student visa guidance for Master's programs in Computer Science fields across the UK, USA, Canada, and more
  • βœ… Comes with job placement support and a 90-day success plan once you land a role
  • βœ… Offers a 1-year internship experience letter while you studyβ€”all with no hidden costs

It's not just a diplomaβ€”it's a career accelerator.

πŸ‘‰ Start your journey today with a 7-day free trial

Related Articles

Continue exploring with these handpicked articles that complement what you just read

21 min read

LFCS Part 38: Text Transformation with tr

Master the tr command for character-by-character text transformation. Learn case conversion, character deletion, squeezing repeats, and complement sets for efficient text processing.

#Linux#LFCS+6 more
Read article

More Reading

One more article you might find interesting