Not sure where to put this, since there isn’t a category for script questions. Maybe there should be one?
I’ve been looking for a simple command in Terminal to sum all the file sizes as reported by the ls command. I have yet to find one so I came up with this rather long winded thing.
First some data to work with, very short example (ls -l):
-rw-r--r-- 1 qruqs qruqs 119783380 18 aug 14.42 20240818-002.066
-rw-r--r-- 1 qruqs qruqs 532988 18 aug 14.36 20240818-002.par2
-rw-r--r-- 1 qruqs qruqs 3696180 18 aug 14.36 20240818-002.vol0003+0004.par2
drwxr-xr-x 8 qruqs qruqs 36864 18 aug 11.50 Deep
Then, to get to the thing I want, I have to do the following dance:
$ ls -l | grep "^-" - | cut -d "s" -f 3 | rev | cut -d " " -f 5 | rev | paste -s -d"+" | bc
30057817328
Which is the same number as reported back to me if I go to that directory and select all 81 files, right-click the selection and choose Properties.
That’s nothing short of being ridiculous! There must be a better way.
What is it?
Thanks for any ideas or solutions.