-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive warning for find #4
Comments
You're quite right: it should not be complaining when using -print0. I'll fix this shortly. You did ignore its advice and used "-exec {} ;" instead of "-exec {} +" though, which is why your alternative is slower :P |
Thanks for fixing! Actually, even with exec {} +, find is notably slower than xargs. The main reason is that it blocks the find process while doing a block of exec. $ time find . -type f -exec ls -d >/dev/null {} + real 0m3.790s real 0m3.779s real 0m3.806s real 0m3.122s real 0m3.157s real 0m3.185s ... and never mind that you can also pass -P NNN to xargs :P $ time find . -type f -print0 | xargs -0 -P 8 ls -d >/dev/null real 0m0.810s |
Shellcheck no longer warns about piping find to xargs -0 |
This warning is invalid:
find ... -print0 | xargs -0 ... handles whitespace.
And piping to xargs can be orders of magnitude(!) faster than using -exec {}, which is single-threaded, blocking, and not file system cache friendly:
$ rm -f /tmp/foo; time find /usr/lib64 -type f 2>/dev/null -print0 | xargs -0 md5sum >>/tmp/foo 2>/dev/null
real 0m3.304s
user 0m2.971s
sys 0m0.373s
$ rm -f /tmp/foo; time find /usr/lib64 -type f 2>/dev/null -exec md5sum >>/tmp/foo {} ;
real 0m14.842s
user 0m4.928s
sys 0m5.174s
If anything, the warning should be the other way - never use exec {} if there's an opportunity to use -print0 | xargs -0
The text was updated successfully, but these errors were encountered: