[NTLUG:Discuss] searching text in all files for match

Fred James fredjame at concentric.net
Wed Jun 5 22:31:51 CDT 2002


Warning: In UNIX everything is a file.  Time aside (and I admit that 
time can be a problem), the only serious issue I have with any of these 
solutions is what happens when they run into "different" files - stuff 
that ain't just text.  They can get locked, error out, or if the output 
is redirected to a file, they can even fill all available space.  This 
from actual testing this afternoon.  That means you will need some means 
of protecting the processes from "different" files, such as searching 
only directories that contain "safe" files.  Don't just turn it lose on 
your whole file structure.


kbrannen at gte.net wrote:

> 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' {} \;
> 
> 
> 
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
> 
> 


-- 
"Wisdom begins in wonder." - Socrates





More information about the Discuss mailing list