Top 10 du commands in Linux

Top 10 du commands in Linux

Here are my top 10 du commands with examples:

Disk usage for all files in dir

This is the most basic usage of the du command:

du /path/to/folder
du1 - Top 10 du commands in Linux

Human Readable format

By default du command prints size in Disk Blocks, to use human-readable format (KB, MB, GB, etc.) use the -h or –human-readable argument.

du -h /path/to/folder
du2 - Top 10 du commands in Linux

Total size of folder

Use -s or –summarize to display only a total for each argument:

du -sh /path/to/folder
du3 - Top 10 du commands in Linux

No disk usage for subfolders

print the total for a directory

du --max-depth 1

or

du -d 1
du4 - Top 10 du commands in Linux

Sort by modification date

Show time of the last modification of any file in the directory, or any of its subdirectories

du -ha --time /path/to/folder
du5 - Top 10 du commands in Linux

Sort by size

du -d 1 | sort -n -r
du6 - Top 10 du commands in Linux

Top 5 files/folders by disk size

du -a /path/to/folder | sort -n -r | head -n 5
du7 - Top 10 du commands in Linux

Top 5 files by disk size

find /path/to/folder -type f -printf "%s %p\n" | sort -rn | head -n 5
du8 - Top 10 du commands in Linux

Exclude .txt files

du -ah --exclude="*.txt" /path/to/folder
du9 - Top 10 du commands in Linux
whoami
Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.