>> find . -type f -name "*" -print | xargs "grep" "search string"
>>
>> ...does not exhibit this behaviour.
Matthew> I would be wary using shell metacharacters ("*") in any
Matthew> command that requires all names in a current directory. In
Matthew> some cases of very large directories, it may cause the shell
Matthew> to expand the line to something too large for UNIX to run.
But the shell isn't expanding the metacharacter, because it is in
quotes. And the purpose of xargs is to ensure that the command line
never gets too big. The find command above works almost perfectly.
The only problem would be if xargs ended up splitting up its input
into more than one batch of files, and the second batch had a single
file. Then, if grep matched a string in that single file, you wouldn't
know which file had the match. Of course, this exception is a little
pathological...
Matthew> Use:
Matthew> find . -type f -exec grep -l '<string>' {} \;
This is OK, but slow, especially if there are a lot of files, because
you have to exec grep once for each file. Also, if the original poster
wants to see the pattern that matched, then grep -l won't do it. Of
course, without the -l, you won't see which filename contained the
match. A slightly better solution is to force grep to print the
filename and the match by passing two files to grep each time:
find . -type f -exec grep "string" {} /dev/null \;
Cheers,
^
Dave Carrigan /|\ Northern Forestry Centre
Systems/Network Administrator | Unix/VMS/TCP-IP/DECnet/Pathworks