List of directories, sorted by size of contents
Its often a pain to get the syntax just right if you're not someone who does a ton of server admin. This shell command ( ubuntu ) will give you a list of directories, sorted by size, in human-readable size notation.
du --max-depth=1 -k * | sort -nr | cut -f2 | xargs -d '\n' du -sh
Some *nix systems won't support --max-depth
but will support -d
for the same result, and some won't support then -d option for xargs in which case you can do something a bit more convoluted ( MacOS example )
du -d 1 -k * | sort -nr | cut -f2 | tr '\n' '\0' | xargs -0 du -sh
This version sends the results of cut
to tr
which replaces the newlines with nulls, and then tells xargs to expect null terminated arguments. The first version - which is a more modern version of xargs - allows you to specify what terminates an argument (so in the first version we explicitly tell it newline).
Happy directory sorting!
Written by Erik Wurzer
Related protips
2 Responses
Beautiful :)
btw this will work on practically any distro and probably BSD, not Ubuntu specific at all