[clue-tech] question on commands

David Anselmi anselmi at anselmi.us
Thu Mar 10 18:25:48 MST 2005


mike havlicek wrote:
> Its always fun to put a little grep in the exec option
> too (echo and redirect for more fun) ... rather than
> the edit.
[...]
>>$ find -name filename -exec vi {} \;

No, I'd say you're almost always better off piping find to xargs when 
using grep:

$ find . -name filename | xargs grep foo

Using -exec starts grep once for each file (a fork/exec each time). 
That's slow with lots of files and since grep only gets one file it 
doesn't print the file name in its output--all the output is run 
together with no way to tell what file each line came from.

For vi I would say the same.  For Jeff's case he may expect only one 
file from find.  But if he gets more than one and uses -exec, he'll vi 
the first, quit, vi the next, quit, so on.  A pain if he gets a lot of 
files.

Piping to xargs is generally the same as:

$ vi $(find . -name filename)

except that you can get a command line that is too long--which is what 
xargs is made to handle.

Dave



More information about the clue-tech mailing list