4

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.

Ray Andrews
  • 2,347
  • Is the sorting still wrong without the grep? I'm thinking maybe there are other values being sorted in the middle that might somehow make this make sense? I am having trouble imagining how, to be honest, but can you check, just in case? – terdon Mar 01 '24 at 19:16
  • Removing the grep doesn't change the order. Mind, if files are included they are in perfect order by size, it's only directories themselves that aren't. I'd just assume that the sort only applies to files, except that the directories are sorted too, just not perfectly. – Ray Andrews Mar 01 '24 at 20:01
  • I don't suppose this is one of those things where the allocated size on the disk is one thing, but the actual cumulative sizes of the files is another thing? – Ray Andrews Mar 01 '24 at 20:05
  • Which version of tree are you running? 1.8.0 or earlier perhaps? – Stephen Kitt Mar 01 '24 at 20:09
  • 1.8.0 ............ – Ray Andrews Mar 01 '24 at 21:40

1 Answers1

4

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.

Stephen Kitt
  • 434,908