[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grep -r problem
From: |
Bob Proulx |
Subject: |
Re: grep -r problem |
Date: |
Sat, 10 May 2003 10:56:09 -0600 |
User-agent: |
Mutt/1.3.28i |
Eli Zaretskii wrote:
> > Russ Koyle writes:
> > grep -l -r void *.c
> > grep: *.c: No such file or directory
>
> That's because you misunderstand the meaning of -r. It does _not_
> search *.c files in all subdirectories; instead, it recursively
> searches in all subdirectories whose names match *.c.
Yes. But I think your explaination has a dangling modifier which
makes it ambigous still. Let me attempt to improve upon it.
The shell expands *.c before the command ever sees it. Use 'echo' to
look at what is getting executed. In the case that there is no match
then the literal * will get passed through.
But grep -r does not want files, it wants directories. Here is a
short key to what you want.
grep without -r wants files
grep with -r wants directories
Examples:
grep void *.c
grep -r void .
That greps every file and not just *.c files as your originally
asked. But machines are so fast these days that many consider that
fine. But if you want to avoid that, and also do this the traditional
way, then you could use find and xargs.
find . -name '*.c' -print0 | xargs -r0 grep void
You should read the FAQ on this subject. Look for "recurse" and you
will find a discussion of 'rm -r' with the same concepts.
http://www.gnu.org/software/fileutils/doc/faq/
Bob