Skip to content
FLAVIO COPES
flaviocopes.com
2026

Linux commands: du

By Flavio Copes

Learn how the Linux du command shows the disk space used by files and directories, with du -h for human-readable sizes and sorting by size using sort -nr.

~~~

The du command will calculate the size of a directory as a whole:

du

Terminal showing du command output with size 32 displayed in bytes

The 32 number here is a value expressed in bytes.

Running du * will calculate the size of each file individually:

Terminal showing du * output listing individual Vue file sizes, each showing 8 bytes

You can set du to display values in MegaBytes using du -m, and GigaBytes using du -g.

The -h option will show a human-readable notation for sizes, adapting to the size:

Terminal showing du -h output with human-readable sizes in K for various vuehandbook directories

Adding the -a option will print the size of each file in the directories, too:

Terminal showing du -ah output listing both directories and individual files with their sizes

A handy thing is to sort the directories by size:

du -h <directory> | sort -nr

and then piping to head to only get the first 10 results:

Terminal showing du -h piped to sort -nr and head, displaying top 10 largest directories by size

The du command works on Linux, macOS, WSL, and anywhere you have a UNIX environment

~~~

Related posts about cli: