Home·Terminal commands

du

Files and directories

Usage

du -sh [path]

Adds up the disk space files actually occupy; it counts allocated blocks, so its total differs from the sum of file sizes and from df.

Common flags

FlagMeaning
-sOne total per argument instead of every subdirectory
-hReadable sizes such as 1.2G
-aInclude files, not only directories
-dLimit the depth; GNU also spells it --max-depth
-xStay on one filesystem
-cPrint a grand total at the end

Examples

du -sh *

Size of every item in this directory.

du -h -d 1 / | sort -h

Top-level directories, smallest to biggest.

du -shx /var

Size of /var without crossing into other mounts.

Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does du do?

Adds up the disk space files actually occupy; it counts allocated blocks, so its total differs from the sum of file sizes and from df.

Q. How do I type it?

du -sh [path] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man du. This command sits under Files and directories.

Related commands

man page: man du