CIS120 Linux Fundamentals by Scott Shaper

Disk Usage & Filesystems

When a Linux system feels “broken,” a very common cause is not software—it is storage. If a disk (or partition) fills up, programs cannot save data. This leads to real problems:

In other words, a “full disk” can make a healthy system look completely broken.

This lesson teaches you how to answer one key question:

“Where did all my disk space go?”

Try it with provided snapshot files (diff + sed)

Before using real system commands, we practice on saved outputs in ~/playground/chapter9. This helps you focus on reading and understanding output instead of being overwhelmed by a live system.

Real troubleshooting usually works like this:

We can use the diff and sed commands we learned in the previous lesson to practice on saved outputs.

diff -u compares two files and shows changes in a readable format.

sed -n '/pattern/p' means:

Example: '/\/var\/log/' matches the text /var/log. The slashes are escaped because / is used as a delimiter.

Practical Examples

# Go to the practice folder
cd ~/playground/chapter9

# Compare “before vs after” disk usage (what changed?)
diff -u df_before.txt df_after.txt

# Compare “before vs after” directory breakdown for /var
diff -u du_var_before.txt du_var_after.txt

# Extract just the /var/log line from the "after" breakdown
sed -n '/\/var\/log/p' du_var_after.txt

Goal: Notice that /var/log grew. This is a very common real-world issue.

Disk Usage Commands

In this lesson, we will be using the following commands to find out where the disk space is going:

Quick Reference

Command What It Shows
df How full each filesystem is
lsblk Physical disks and partitions
findmnt How paths map to filesystems
du What directories/files are using space

Important idea: These tools answer different parts of the same problem.

Find the filesystem that is full (df)

The df command shows disk usage by filesystem (not individual folders).

Think of a filesystem like a “container” that holds directories such as / or /home.

Run:

df -h

Focus on this column:

If you see something like 98% or 100%, that is your problem.

Key idea: df tells you which filesystem is full, not what inside it is causing the problem.

df [options] [mountpoint_or_path]

Common Options

Option What It Does When to Use It
-h Human-readable sizes Almost always
-T Show filesystem type For troubleshooting
-a Show all filesystems For deeper inspection
-t type Filter by type Focus on specific storage
-x type Exclude type Ignore temporary filesystems
--total Show totals Quick overview

Practical Examples

# Human-readable disk usage by mount point
df -h

# Sometimes helpful: include filesystem type
df -hT

Understand disk/partition layout (lsblk)

lsblk shows how storage is physically organized.

Key terms:

Analogy:

lsblk [options]

Use -f to connect partitions to filesystems and mount points.

Practical Examples

# View disks/partitions + filesystem info
lsblk -f

When you run lsblk -f, the output shows a “tree” of storage devices:

This is an example of the output:

lsblk -f output

In the screenshot, you can use MOUNTPOINT to spot which devices are actually visible in the directory tree (for example, items mounted at /boot, /boot/efi, or /home/students). Once you know the mount point, you can interpret disk-full symptoms with df and find large folders with du.

Why this matters: It helps you connect what df shows (mount points) to actual devices.

Map a path to its mount point (findmnt)

A mount point is where a filesystem appears in the directory tree.

Example:

findmnt answers:

“What filesystem is this directory on?”

findmnt [path]

Practical Examples

# See mount information for a path
findmnt /

# See mount information for /home
findmnt /home

Why this matters: You must stay inside the correct filesystem when troubleshooting disk usage.

Find what directories are taking space (du)

du shows how much space directories and files are using.

This is where you actually find the problem.

Strategy:

du [options] path

Key Concepts

Think of this pipeline:

du → clean output → sort → find biggest

Practical Examples

# Show top-level directories under /home (skip unreadable parts)
du -h --max-depth=1 /home 2>/dev/null | sort -h

# Show top-level under /var (often contains logs/cache)
du -h --max-depth=1 /var 2>/dev/null | sort -h

# If you find a big folder, go one level deeper
du -h --max-depth=1 /var/log 2>/dev/null | sort -h

Real-world tip: /var/log is one of the most common causes of disk filling up.

Disk Full Workflow (Putting It All Together)

When troubleshooting disk space, always follow this order:

Simple mental model:

If you remember nothing else from this lesson, remember that workflow.