[NTLUG:Discuss] searching text in all files for match
Cameron Moore
lists at unbeatenpath.net
Wed Jun 5 23:15:53 CDT 2002
Try this:
find . -type f | perl -lne 'print $_ if -T;' | xargs grep 'whatever'
Enjoy
* fredjame at concentric.net (Fred James) [2002.06.05 22:39]:
> 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:
> >
> >>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.
> >
> >>
> >>find / -type f -print -exec fgrep "text to find" {} \;
> >>
> >>find . -exec grep -l 'text to search for' {} \;
--
Cameron Moore
/ Berkely, CA: It's like taking a tour \
\ of a sewer in a glass-bottom boat. /
More information about the Discuss
mailing list