du notes

du is the linux command to show disk usage.

To show usage of all files in a [directory], in human-readable (-h) format:

du -h [directory]

To show a summary (-s) of a [directory]:

du -hs [directory]

Drop the -h flag if you want usage in Kilobytes (KB).

Excluding files

Use the --exclude option to exclude files by pattern:

me@pc ~ $ du -hs personal
31G	personal
me@pc ~ $ du -hs personal --exclude='personal/media/*'
6.7G	personal
me@pc ~ $ du -hs personal --exclude='personal/media/*' --exclude='personal/backups/*'
2.4G	personal

Order directories by disk usage

This bash script will order by usage the subdirectories of the directory given:

du -sk * | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done

As a bash function:

function duf {
du -sk "$@" | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done
}

Usage:

me@pc ~/mindspill/output $ duf .
69M	.
me@pc ~/mindspill/output $ duf *
8k	privacy
8k	test
12k	index.html
12k	site-styling
72k	junk
72k	sitemap.xml
80k	manager
92k	biking
301k	miscellany
473k	search
1M	tags
5M	computing
9M	assets
50M	links

References

Last modified: 24/03/2015 Tags:

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top