[Novalug] bash commands

Richard Rognlie rrognlie@gamerz.net
Fri Jan 18 15:21:06 EST 2008


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...

> -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.


-- 
 /  \__  | Richard Rognlie / Sendmail Ninja / Gamerz.NET Lackey
 \__/  \ | http://www.gamerz.net/~rrognlie    <rrognlie at gamerz.net>
 /  \__/ | Creator of pbmserv@gamerz.net
 \__/    |                Helping reduce world productivity since 1994



More information about the Novalug mailing list