Skip to content

du

11 commands

Estimates how much space files and directories use — find what is filling a disk.

  • disk
  • storage

Install du

sudo apt install coreutils

Basics6

du -sh <dir>

Total size of a directory, human-readable.

Link
du -sh *

Size of each item in the current directory.

du -sh .[!.]* *

Includes hidden files and directories.

du -h --max-depth=1 <dir>

One level of subdirectories (on macOS use -d 1).

Link
du -ah <dir>

Lists files as well as directories.

Link
du -c <files>

Adds a grand total.

Link

Finding space hogs5

du -sh * | sort -h

Sorted smallest to largest.

Link
du -ah <dir> 2>/dev/null | sort -rh | head -n 20

The 20 largest files and directories.

Link
du -xh --max-depth=1 / 2>/dev/null | sort -h

Stays on one file system (-x) so mounted volumes are not counted.

Link
du -sh --exclude=<pattern> <dir>

Leaves out matching paths.

Link
du --apparent-size -sh <file>

Shows the logical size, which differs from disk usage for sparse files.

Link