LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


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.
Rate this Entry

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")

Code:
find . -maxdepth 1 -printf %k"000\n" | awk '{  sum += $1 } END { print sum }' | numfmt --from=auto --to=iec-i
I was annoyed with the fact that "du", with whatever parameters I tried to get only the usage for the files on the root of the current folder (i. e., non-recursive), took ages to give the result, while the value comes comparatively instantaneously when you're browsing the folders on a file manager like Konqueror or some other, with that indication. I don't know what are the inner workings of these file managers, but it seems much more time-effective than du.

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
Posted in Uncategorized
Views 8232 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 01:51 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration