Recursion with grep?

Jerry McAllister jerrymc at clunix.cl.msu.edu
Thu Nov 13 15:15:27 PST 2003


> 
> --- Matthew Hunt <mph at astro.caltech.edu> wrote:
> > On Thu, Nov 13, 2003 at 05:37:39PM -0500, Francisco Reyes wrote:
> > 
> > > The man page for grep says to use "-r" to recurse, yet when I try
> > > something like
> > > 
> > > grep -r -li string *.c
> > > 
> > > I get no files. However, if I go into one of the subdirectories and do
> > a
> > > plain grep <string> *.c then <string> is found on several files.
> > 
> > When using "-r", the arguments to grep should be directories.  It will
> > process all of the files in the given directories, recursively.  There
> > is
> > no provision for searching a subset of the files (i.e. "*.c).  If you
> > need to do that, use find and xargs.
> > 
> 
> You can also do this with something like:
> 
> ls -laR | egrep *.c
> 
> chris

Not as elegant maybe, but you can also do something like
  ls -li string *.c
  ls -li string */*.c
  ls -li string */*/*.c
   etc...
Using the shells uparrow to repeat the command makes that easy
if you only have a few directory levels to peruse.

////jerry



More information about the freebsd-questions mailing list