How to list subdirectories recursively with total size

Just a note to myself, as I always have a hard time understanding the find manpages. To list the directories and subdirectories up to a certain depth, “simply” enter:

[bash light=”1″]
find . -maxdepth 2 -type d
[/bash]

Option maxdepth states how deep the subdirectories should be listed, option type restricts output to directories (d).

If a directory listing including size is required, this much shorter snippet does the trick, using du (disk usage), the counterpart to the often-used df (disk free):
[bash light=”1″]du -hd 1[/bash]

Option h triggers human-readable output, replacing size byte count (5820) with SI prefixed numbers (5.8K), while d limits the recursion depth like before.


Posted

in

,

by

Tags: