Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • See also Why is looping over find's output bad practice? and Is it possible to use `find -exec sh -c` safely? Commented Apr 19, 2023 at 12:55
  • If you're using find, you don't really need to use xargs, (almost) everything it does can be done with find's -exec predicate, especially when combined with sh or some other scripting language (e.g. -exec sh -c '...' or -exec perl- e'...'. xargs is more useful with other programs (i.e. programs-that-aren't-find). About the only time it's useful to use xargs with find is when you need parallel execution with xargs -P (and even then, there's often better tools for that job, like GNU parallel) Commented Apr 19, 2023 at 12:58
  • @cas, 👍 on that, see also find . -print0 | xargs -0 cmd vs find . -exec cmd {} + Commented Apr 19, 2023 at 13:01
  • oh yeah, filtering/manipulating the file list with grep/sed/awk/perl/whatever (NUL-separated, of course) between find ... -print0 and xargs -0r is also a good reason to use xargs instead of -exec. Commented Apr 19, 2023 at 13:05