On Wed, 11 Aug 2004, Aaron Gaudio wrote:
On Wed, 2004-08-11 at 14:51 -0400, Robert P. J. Day wrote:On Wed, 11 Aug 2004, Alexander Dalloz wrote:
Am Mi, den 11.08.2004 schrieb Kevin Old um 20:31:
I've been using find . -exec grep "phrase I want" {} \;
Not the best way. Using -exec is problematic.
why problematic?
I think the main complaint is that it is slower, having to exec a new grep process for each file find encounters, versus piping to xargs (which will be faster overall, but provide less running feedback).
i was just about to post on just this issue. if you want to process a bunch of files recursively (and the command itself doesn't support recursive operation), there's
1) find . -exec <cmd> etc etc ...
drawback: as above, a new exec for every single file. blah.
2) <cmd> $(find . criteria here)
let "find" do the work of finding the file names, and just run <cmd> once. much faster, but ...
drawback: depending on the number of files, you could literally overflow the shell command line limit as the shell tries to construct the command.
which leaves a compromise:
3) find <criteria> | xargs <cmd>
grab a bunch of files at a time, and process them. combines both of the benefits of the above, while avoiding the drawbacks.
of course, if the command has recursive behaviour, it's a no-brainer.
rday