Luke Oliff.

TIL: Finding Disk Usage Per Directory With du -sh

·TIL·1 min read·Luke Oliff

Disk full. Where did it all go? du -sh tells you per directory.

du -sh *

Human readable sizes for every item in the current directory. Find the folder that is eating your disk.

du -sh ~/Projects/* | sort -rh

Sort by size, largest first. The -r flag reverses the sort and -h makes it understand human readable suffixes.

du -sh --exclude=node_modules ~/Projects/* | sort -rh

Exclude node_modules. Without this every JavaScript project looks like it is eating all your disk space.

du -sh ~/Downloads/*/ | sort -rh | head -10

Top 10 largest folders in Downloads. Find the zip file you downloaded once and never opened again.

What is the difference between du and df?

df shows total disk usage per mounted volume. du shows usage per directory or file. du is for finding the culprit, df is for checking the damage.