Skip to content

Disk usage

df tells you how much space is left. To find out what is using it, use du (disk usage).

Terminal window
du -sh /var/log
  • -s: summary, a single total instead of every subdirectory.
  • -h: human-readable sizes.
Terminal window
du -h --max-depth=1 /var | sort -hr | head -20
  • --max-depth=1: only one level down.
  • sort -hr: sorts human-readable sizes (-h), largest first (-r).

Run it again on the biggest directory to drill down level by level.

To stay on a single filesystem and not wander into other mounts (/proc, network shares, other disks), add -x:

Terminal window
sudo du -xh --max-depth=1 / | sort -hr | head -20
Terminal window
sudo find / -xdev -type f -size +500M -exec ls -lh {} + 2>/dev/null
  • -xdev: don’t cross into other filesystems.
  • -size +500M: files larger than 500 MB.
  • 2>/dev/null: hides the “Permission denied” noise.

The 20 biggest files under a directory:

Terminal window
find /var -xdev -type f -printf '%s %p\n' 2>/dev/null | sort -nr | head -20 | numfmt --field=1 --to=iec

If it’s installed (or you can install it), ncdu is the most comfortable option: you browse with the arrow keys and can delete from inside the tool.

Terminal window
sudo ncdu -x /

du and df won’t always agree. If df shows much more space used than du can account for, check for deleted files that are still open:

Terminal window
sudo lsof +L1