Find big directories using du and (e)grep

Alec Jacobson

March 25, 2010

weblog/

Here's a simple script I'm using to locate big directories (larger than 1GB):
du -h | grep "^ *[0-9][0-9.]*G"
The output looks like this:
1.1G	./Art/2007
2.5G	./Art/2008/Party Freakz Pasta Party
6.3G	./Art/2008
9.2G	./Art
 24G	./Documents/Parallels/Windows 7.pvm/Windows 7-0.hdd
 24G	./Documents/Parallels/Windows 7.pvm
 24G	./Documents/Parallels
 26G	./Documents
2.5G	./Downloads/enstrophy-big-endian
 33G	./Downloads
...
100G	.
Here's how I find big directories greater than 100MB:
du -h | egrep "^ *([0-9][0-9][0-9][0-9.]*M)|([0-9][0-9.]*G)"
To list files, too, just add the -a flag to du like this:
du -ah | grep "^ *[0-9][0-9.]*G"