tree command with 'sort=size' seems imperfect

I’m trying to sort by size:

% tree -axCF --du --sort=size | grep -e '/$' 

├── [    8658884]  2022-10-09-backup/
├── [    5923934]  f24-01-22-backup/
├── [    5384825]  e2023-01-19-backup/
├── [    3627525]  h24-01-22-npanelize-nselect/
├── [    2162140]  b2022-12-18-backup/
├── [    1255661]  a2022-12-12-backup/
├── [     996252]  2021-08-12-backup/
├── [     647677]  2022-11-20-backup/
├── [     133361]  Test/
├── [      95801]  Boneyard/
├── [       1024]  g24-01-22-backup/         < Ooops
├── [      16031]  Misc/
├── [       1024]  Temp/                     < Ooops      
├── [     449317]  Znt/
│   ├── [     158892]  Boneyard/
│   └── [     199717]  VirginN-functions/
│       ├── [      34739]  backup.1/       < Nothing right in this dir
│       ├── [      29896]  Source/
│       ├── [      35481]  Text/
│       └── [      98577]  virgin/

… as we see, it’s not too bad, however there are a few anomalies. Is there some reason for this? Can I do anything about it?

BTW the ‘grep’ is because, AFAICT, ‘tree’ won’t show you directory content sizes, even if you use ‘–du’, unless you show all files too (you can’t use ‘-d’), and since I don’t want to show files I use grep to filter them out. This seems weird, but thereyago.

Asked By: Ray Andrews

||

tree versions 1.7.0 and 1.8.0 didn’t take --du into account when sorting by size: directories were sorted by their own size, not the size of their contents. This was fixed in version 2.0.0.

Answered By: Stephen Kitt
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.