I often use
du --max-depth=n -h | sort --human-numeric-sort
Now I want to use tree
, in a similar manner.
I found here a partial answer
tree -sh --sort=size --du
where --du
makes tree
reporting the cumulative size for each directory (as du
).
This reports each file as well.
If I want to report only directories, I should add -d
to tree
.
But -d
seems to do two things:
- Remove files from the report.
- Remove the size of files from the cumulative total computed for each dir.
Of course, I want only 1, not 2 (as du
does).
So
tree -sh --sort=size --du -d
would always report "small" sizes, without considering file sizes.
Can tree
overcome this? Is there any alternative?
This is definetely a shortcoming of
tree
. It only summarize sizes of "what it sees". If you ignore files with-d
or-I
or if you limit the depth,tree
will report a "wrong" dir size.If you don't need to restrict levels, this works fine:
Wiht
01;34
being the color value for directories fromLS_COLORS
env variable (...di=01;34...
).If you want to restrict levels though, the deepest level will still report wrong dir size with this method.
Consider using a more advanced tool such as
ncdu
.See also this very similar question at U&L SE.