The Linux du Command: Finding Directory Sizes

The Linux du Command: Finding Directory Sizes

When disk space is tight, you need to find what's eating it. du shows directory space usage - here's how to use it effectively.


Basic Usage

Current directory

du

Shows all subdirectories with sizes.

Human readable sizes

du -h

Shows KB, MB, GB.

Total only

du -sh .

Total size of current directory.


Practical Examples

Largest subdirectories

du -h | sort -h | tail -10

Sort and show top 10.

Specific directory

du -sh /var/log

Total for /var/log.

All levels

du -h --max-depth=1

One level deep only.

Exclude patterns

du -h --exclude='*.log'

Ignore log files.


Quick Reference

Flag What It Does
-h Human readable
-s Total only
-a All files
-d N Max depth
--exclude Skip pattern

Further Reading