Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
A much faster "du" alternative for the current folder (non-recursive)
Posted 06-17-2014 at 09:55 PM by the dsc
Updated 06-17-2014 at 10:21 PM by the dsc (grammar, "benchmarks")
Updated 06-17-2014 at 10:21 PM by the dsc (grammar, "benchmarks")
Code:
find . -maxdepth 1 -printf %k"000\n" | awk '{ sum += $1 } END { print sum }' | numfmt --from=auto --to=iec-i
The one-liner above is a slight change over something I've found in this very forum:
https://www.linuxquestions.org/quest...folder-140208/
I just added maxdepth=1, and "000" missing to make up Kbs, which seems to be more often the case, and results in correctly human-readable output from those "numfmt" parameters, which I also added from somewhere else. But it's probably not the best way to go about doing it, math-wise, and disk-usage-technical-wise.
It seems to be specially faster than "du" on folders with lots and lots of files, but to my astonishment "du" is actually faster sometimes.
Two comparisons with "time"
du -Ss:
real 0m6.184s
user 0m0.005s
sys 0m0.100s
find-awk-pipe-thing:
real 0m0.131s
user 0m0.010s
sys 0m0.011s
In another folder, in the reversed sequence (trying to counterbalance some eventual disk-cache effect of soe sort):
find-awk-pipe-thing:
real 0m3.266s
user 0m0.013s
sys 0m0.050s
du -Ss:
real 0m6.839s
user 0m0.015s
sys 0m0.196s
Total Comments 0