On Fri, May 31, 2024 at 06:57:27AM +0800, Northwind wrote: > both the size of current path and subdir should be expected.
According to the man page, that's what it does. I just installed tree and tried it. There's a subtle behavior that I did not expect: hobbit:/usr/local$ tree -d --du -h [3.9M] . ├── [4.0K] bin ├── [4.0K] etc Those number are definitely not totals for the files in a directory. Compare: hobbit:/usr/local$ tree --du -h | less [627M] . ├── [ 81M] bin │ ├── [7.6K] addcr It looks like the -d option makes it only look at the size of the raw directory (4096 bytes, as in hobbit:/usr/local$ ls -ld bin drwxr-sr-x 2 root staff 4096 Feb 17 15:14 bin/ ) rather than the total of the files within the directory. Solution: don't use -d. But then you get all the files listed instead of just the directories. If there's a way to get the pruning of files of -d plus the total-printing of omitting -d then I don't know what it is. The best workaround I can immediately see is to include -F to put trailing slashes on the directories, and then grep for those. hobbit:/usr/local$ tree --du -h -F | grep /$ | head [627M] ./ ├── [ 81M] bin/ ├── [4.0K] etc/ ├── [4.0K] games/ ├── [126K] include/ │ └── [122K] opus/ ├── [ 42M] lib/ │ ├── [3.4M] nethackdir/ │ │ ├── [4.0K] save/ │ ├── [4.3K] pkgconfig/