Re: [dev] Why not use the -exec feature of find?

From: Lee Phillips <lee_AT_lee-phillips.org>
Date: Tue, 22 Jun 2021 07:30:44 -0600

> All over the place (tutorials, manuals, articles, questions and answers) I see the advice to use the null feature of find (-print0) and xargs (-0) to be able to handle any kind of wacky file name (e.g. filenames with newlines). Granted, *if* you are going to pipe find into xargs, the advice makes sense. But wouldn't it be better in every way to use the -exec (or -execdir) feature of find instead of piping into xargs? Why isn't that the common advice? Is the -exec feature of find fairly new, or fairly new to Posix?

I usually use -exec (I don't think it's new), but the xargs method is required if you want to stop execution on a failed subcommand; the -exec version will just go on to the next file. If you have a huge number of files and multiple cores you may want to use the xargs method, as it can easily be parallelized.
Received on Tue Jun 22 2021 - 15:30:44 CEST

This archive was generated by hypermail 2.3.0 : Tue Jun 22 2021 - 16:12:07 CEST