Skip to content

Instantly share code, notes, and snippets.

@mjgaylord
Created February 27, 2010 10:11
Show Gist options
  • Save mjgaylord/316615 to your computer and use it in GitHub Desktop.
Save mjgaylord/316615 to your computer and use it in GitHub Desktop.
http://www.cyberciti.biz/tips/linux-unix-du-command-examples.html
du command Examples
Type du to display usage in current directory :
$ du
Pass -h option to display output in Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte (Human-readable output)
$ du -h
Display the name and size of each png file in the /ramdisk/figs/ directory as well as a total for all of the pngs:
$ du -hc /ramdisk/figs/*.png
Another useful option is -c which produce a grand total:
$ du -c
Show the disk usage of the /home/vivek subdirectory:
$ du /home/vivek
Show only a summary of the disk usage of the /home/vivek
$ du -hs /home/vivek
Exclude files that match PATTERN. For example do not count *.obj or *.jpg files:
$ du -h --exclude='*.obj'
$ du -h --exclude='*.jpg'
A PATTERN is a shell pattern (not a regular perl or other expression). The pattern ? matches any one character, whereas * matches any string.
Pipes and filters with du
Now display everything sorted by filesize:
$ du -sk .[A-z]* *| sort -n
Display screenful output at a time as du generate more output than can fit on the console / screen:
$ du -h | less
To find top 3 directories, enter :
$ cd /chroot
$ du -sk * | sort -nr | head -3
4620348 var
651972 home
27896 usr
21384 lib64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment