May 14, 2013
Sometimes, we want to see disk usage in a human readable form (KB, MB, GB) for each subdirectory.
[ytyoun@ladon: ~]# find . -maxdepth 1 -type d -exec du -sh {} \; | sort -h 4.0K ./nsmail 8.0K ./Downloads 8.0K ./.eggcups 8.0K ./.gnome2_private 8.0K ./.gvfs ... 120M ./.mozilla 186M ./emacs-24.2 223M ./.cache 240M ./Desktop 284M ./Work 444M ./.config 1.9G .
How it works.
find
: a linux command to search for files or directories in a directory hierarchy.find .
: runs the find command on the current directoryfind . -maxdepth 1 -type d
: searches for all the directories contained in the current directory without descending to subdirectories below the current directoryfind (condition) -exec (command) {} \;
: for each file or directory satisfied by the (condition), run (command).{} \;
is replaced by each directory satisfied by thefind
command.du -sh (dir)
: displays the disk usage statistics of the directory (dir) in a human readable form.
In this example, we just feed{} \;
as we want to rundu
command for each directory obtained by thefind
command.|
: linux pipesort -h
: sorts the human readable numbers such as KB, MB and GB.
Comments Off on Check which directories hold too much space