Rain WikiWindows · Linux · Android

Disk usage with du and ncdu

Command-line toolAll Linux distributions

du (disk usage) is the standard Linux command that reports how much space files and directories use; ncdu is an interactive, ncurses-based alternative that lets you browse the results and delete items. Together with df, which shows free space per file system, they are the usual way to find what fills a disk.

1Useful du options

du -sh /var prints one human-readable total. du -h --max-depth=1 / lists the size of each top-level directory. -x stays on one file system, so mounted disks and /proc are skipped.

Piping to sort finds the biggest items: du -xh --max-depth=1 / | sort -h.

2ncdu

ncdu -x / scans the root file system and opens a browsable list sorted by size. Arrow keys move, Enter opens a folder, 'd' deletes the selected item after confirmation, 'q' quits. ncdu is usually installed from the distribution's package (for example apt install ncdu).

3When du and df disagree

If df reports a full disk but du finds less, a deleted file may still be held open by a running process. The space returns when that process closes the file or restarts.

How to find what fills the disk

  1. See which file system is full: df -h
  2. List the biggest top-level folders: sudo du -xh --max-depth=1 / | sort -h
  3. Go one level deeper into the largest folder and repeat.
  4. Or browse interactively: sudo ncdu -x /

Cautions

  • Do not delete files you do not recognise in /usr, /lib, /boot or /var/lib.
  • 'd' in ncdu deletes immediately after you confirm; there is no recycle bin.

Sources

  1. du(1) man7.org
  2. ncdu(1) (Debian) manpages.debian.org
  3. df(1) man7.org

Note: RainServer offers monitoring and safe cleanup for Linux servers; it shows what will change and asks first.

Last reviewed: