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.

5
  • 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 1 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. Mar 1 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? Mar 1 at 20:05
  • Which version of tree are you running? 1.8.0 or earlier perhaps? Mar 1 at 20:09
  • 1.8.0 ............ Mar 1 at 21:40

1 Answer 1

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.

4
  • earlier in that case is just the previous version 1.7.0 where --sort was added (and --du added in the previous 1.6.0 one) Mar 1 at 20:25
  • Well then I'd better install the latest. Thanks. Mar 1 at 21:41
  • Sorry for being so lazy. Just found packages.debian.org/source/stable/tree and it's fired up and working fine. Thanks guys. Mar 1 at 22:23
  • ... but I see one still can't use '-d' with '--du' and still get honest sizes. How hard would it be to just make the calculation without actually showing the files? Mar 1 at 22:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .