[Novalug] bash commands
DonJr
djr1952@hotpop.com
Fri Jan 18 15:56:41 EST 2008
On Fri, 2008-01-18 at 15:21 -0500, Richard Rognlie wrote:
> On Fri, Jan 18, 2008 at 03:02:43PM -0500, Joel Fouse wrote:
> > Some grep options I use on a regular basis:
> >
> > -i ... search case-insensitively
> > -r ... search recursively (in the example above, you wouldn't even
> > need the -r if all the files are in the same folder)
>
> Unless the "pattern" you are trying to match (say *.f) results in a very
> large number of matches, and the bash command line balks...
>
> I don't know what that number is, but it's on the order of 1024...
>
Depends on the arch and the amount of aviable memory.
I've seen "glob" break with as little as a 100 files on older systems.
> > -l ... show only the filenames that contain matches rather than
> > displaying each matching line
> > -c ... show all filenames scanned with the number of matching lines
> > contained in each (including zero)
> >
> > As Jeff pointed out, the file parameter isn't limited to a single name;
> > rather, you can use all manner of what they call shell globbing, because
> > the bash shell converts the globs to concrete filenames before passing
> > them on to grep as distinct parameters:
> >
> > grep 'stringToFind' *.[ch] // search for term in all files ending in
> > ".c" or ".h"
> >
> > You can also use multiple filename arguments:
> >
> > grep -r 'stringToFind' ./subDir1/*.[ch] ./subDir3/*.txt ./subDir5
> >
> > Grep is your friend. It's very rare that I need to use some other
> > utility in conjunction with it (cat, find, etc.).
>
> I guess I'm old school... grep -r is "new". and not all unixes support it.
> therefore
>
> find dir | xargs grep pattern
>
> is a habit I use that I *know* will always work.
Not if the file names have spaces or other special characters in them.
Then you need to use the '-print0 ... -0' version of the command.
find dir -print0 | xargs -0 grep pattern /dev/null
--
DonJr
More information about the Novalug
mailing list