📢 Actions Speak Louder Than Words!

Posix - Speed up "find" + "exec" command (recursive)

Posted: Nov 8, 2020 | Reading time: 1 min

I learn some trick today on how to speed up find, exec command. Let check this out:

# let see how many files we have
$ find . -type f | wc -l
36367

# lets check every file status
$ time find . -type f -exec stat {} \; > /dev/null
real    0m40.107s
user    0m14.381s
sys     0m26.410s

# lets check every file status
$ time find . -type f -exec stat {} + > /dev/null
real    0m1.281s
user    0m0.626s
sys     0m0.656s

Wow that’s quite a huge difference! Impressive! All we did was swap the \; for a +.

Explanation? You may refer here1


  1. Martin Tournoij [Carpetsmoker], (2019, May 4). “Making find -exec faster”. https://www.arp242.net/make-find-exec-faster.html  ↩︎

Edit

Discussion and feedback

You can use utterances provided below to post comment on behalf using Github account. Alternatively, you can just send a public comment to my mailing list or send a private message to my e-mail. In a few cases and on certain time, I just don’t have time to moderate them. Please read terms-of-service (ToS) for details.