[PLUG] grep vs find [Was: Re: Unsaved E-mail: Recoverable? [YES, IT IS]]

Fred James fredjame at fredjame.cnc.net
Wed Feb 9 22:13:54 UTC 2011


wes wrote:
> On Wed, Feb 9, 2011 at 11:13 AM, Rich Shepard <rshepard at appl-ecosys.com>wrote:
>
>   
>> On Wed, 9 Feb 2011, Fred James wrote:
>>
>>     
>>> Which is faster for this purpose (if you know), find or grep?
>>>       
>>    Find locates files by name or part of the name. Grep searches for
>> strings
>> within files. Horses for courses (i.e., different tools for different
>> purposes.)
>>
>> Rich
>>
>>
>>     
> You are very correct, find by itself will not look inside of a file.
>
> The two each have their own advantages, and additionally, can be combined
> for extra power and precision.
>
> -wes
>   
find (the directory you want to start with) -type f | xargs file | grep 
-i text | cut -f1 -d: | xargs grep "the string you want"
... is of course no match for elegance when compared to ...
grep -ri "the string you want" (the directory you wish to start in)
... but the question was (if anyone knew off the top of their head) 
which might be faster ... so off I went to do a little bit of testing ...

Preliminary Results
Context is still the biggest issue ... meaning that neither approach 
magically excludes a long list of somewhat irregular files, and 
therefore each may spew out a large quantity of undesirable stuff to be 
waded through.

"stuff to be waded through" means tweaking the command to exclude most 
if not all of that which is "undesirable" while not excluding that which 
is "desirable".

Short answer ... probably not a good idea to run either one beginning with /

YMMV

Preliminary conclusion ... if you can find what you want the way Rich 
did (by reasoning), that would be way cool!

And a tip of the hat to Hal, as well.
Regards
Fred James




More information about the PLUG mailing list