Re: find in conjuction with grep

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

 



to be a little more explicit and to throw an extra trick in your bag,
I usually write tihs up (in scripts, not typically on the command
line) as:

find . -type f -print0 | xargs -0 egrep 'want | phrase' /dev/null

why the /dev/null?  grep will only prepend the filename in the output
if there's more than 1 file.  This guarantees that you'll always have
at least 2 files.

imho, the grep -r option does not belong. but maybe I'm being an old
unix codger.  There's plenty of existing ways to do it. I don't see
the benefit to -r.  It's less flexible than find.

   - Kevin

On Wed, 11 Aug 2004 20:43:10 +0200, Alexander Dalloz
<alexander.dalloz@xxxxxxxxxxxxxxxx> wrote:
> Am Mi, den 11.08.2004 schrieb Kevin Old um 20:31:
> 
> > I've been using
> > find . -exec grep "phrase I want" {} \;
> 
> Not the best way. Using -exec is problematic.
> 
> > for quite a while to search recursively through directories and files
> > to find a phrase or word.
> >
> > The results I get back are simply the line(s) that contained the
> > phrase, but no path or filename.
> 
> find . -print0 | xargs -0 grep "string"
> 
> > I'd thought about the -name flag, but I can't seem to figure out how
> > to use it, though it is more for using to search for file names rather
> > than display the name, it seems.
> 
> find /path/to/search/under -name "*string*"
> 
> will find all object names with "string" anywhere in, like "stringfoo"
> or "foostringbar" or just "string".
> 
> > Kevin
> 
> Alexander
> 
> --
> Alexander Dalloz | Enger, Germany | GPG key 1024D/ED695653 1999-07-13
> Fedora GNU/Linux Core 2 (Tettnang) kernel 2.6.7-1.494.2.2smp
> Serendipity 20:40:56 up 7 days, 14:08, load average: 4.07, 3.31, 2.20
> 
> 
>



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux