[NTLUG:Discuss] searching text in all files for match
kbrannen@gte.net
kbrannen at gte.net
Wed Jun 5 22:16:08 CDT 2002
Fred James wrote:
> That makes 3 lovely ways to do it - Thanks all!
>
> Recap:
> find . -type f | xargs file | grep -i text | cut -f1 -d: | xargs grep
> "search for this"
Just for fun I'll throw this in... Stick with this first one as it has better
performance. The reason being is it will cause many fewer fork/execs
(threads, processes, whatever you want to call them :-) and if you have many
files which match, those extra milliseconds add up quickly. The "find dir
-exec" version will fork off a new process for every file. Read the man page
on xargs if this doesn't make sense.
Kevin
>
> find / -type f -print -exec fgrep "text to find" {} \;
>
>
> find . -exec grep -l 'text to search for' {} \;
More information about the Discuss
mailing list