Beginner · 7 min · practise every command in the built-in terminal

Disk Usage

df — Disk Free (filesystem level)

df shows how much space is used on each mounted filesystem.

df -h              # Human-readable (GB, MB)
df -h /            # Specific filesystem
df -T              # Show filesystem type
df -i              # Show inode usage

Output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   20G   28G  42% /
tmpfs           3.9G     0  3.9G   0% /dev/shm

⚠️ When disk is 100% full, Linux can crash. Monitor with df!

du — Disk Usage (directory level)

du shows how much space directories and files consume.

du -h              # Current directory, human-readable
du -sh             # Summary of current directory
du -sh *           # Size of each item in current dir
du -sh /var/*      # Size of each subdirectory
du -h --max-depth=1 /var    # One level deep

Find large files

# Largest directories in /var
du -sh /var/* | sort -rh | head -10

# Largest files anywhere
find / -type f -size +100M 2>/dev/null

# Sort files by size in current directory
ls -lhS

ncdu — Interactive disk usage browser

ncdu /var

Navigate with arrow keys, press d to delete.

Practice tasks

  1. Show disk space in human-readable format
  2. Show the size of each directory in your home folder
  3. Show disk usage for the root filesystem specifically
  4. Show the total size of the current directory as a single summary

Commands in this lesson

Disk & Memory