Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep resistance



On Sun, 5 Nov 2000, Tony Laszlo wrote:

> Thanks, Jonathan! 
> The following formula did the trick. 
> 
> find . -type f -exec grep -n -C -H STRING '{}' ';' | less 

I wasn't aware of grep's -H flag -- I assume that is only for GNU grep
(which I guess every linux distro has).  Nice.

If you just want the equivalent of 'grep STRING *' though, this will work
and it will be faster since you don't exec a new grep for every file:

ls | xargs grep -n -C STRING

Similarly with find:

find . -type f -print0 | xargs -0 grep -n -C STRING

But, GNU grep also has recursion built in, which presumably would be
faster even than 'find | xargs grep':

grep -r -n -C STRING .
-- 
Tod McQuillin



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links