Well yeah, the answer is technically correct but
I wonder if that is what was intended.
A construction like
find / -name * -print | grep test
lists all the file names and then filters out only
those file names that have the word "test" in
them (and not for example Test or TEST since the -i
flag was not specified for grep).
Another way to interpret the original question may
be "How do I perform a grep through a large number
of files that are located throughout an entire
hierarchical directory structure", for example,
what source code uses this particular function.
Well here Unix gets rather tricky, in theory you
should be able to use the infamous backtick:
it executes the statement inside the ticks and
returns a list with the result, so:
grep test `find / -name *`
Cute and perfectly legal syntax and it works,
kind of, the smarties who implemented the shell
thought it was a great idea to cache the results
in a fixed size bufer, i.e. a construction like
this works as long as the total number of files
is not that great. Guess how many shell scripts have
been put into production only to fail some months later
when the number of files increased.
So... then there was the infamous xargs, which
basically is a hack to get around this, enter:
find / -name * | xargs grep test
the program xargs accepts input from standard input
and executes the command following it every time
it has a number of words. So the grep statement
is executed many times in stead of once in the
previous example.
Then the unix gods got even smarter and decided
to add a "-r" flag to grep, so now you can just
do:
cd / # Go to your directory
grep -r test . # Don't forget the dot !
So... finally.. the real cool thing..
if you do this from within emacs, by using a
compile, you can use the ctrl-x ` command
to step to each of the results one at a time.
For example, say you do search for a function
name in any of the files in the current directory
and everything below that (e.g. header directories,
c++ directories), you enter:
esc-x compile [return]
grep -r -n test .
The results will show up in a separate buffer,
while it is still searching (or when it is
finished) you can type ctrl-x ` to visit
each of the locations, emacs will read the
appropriate file in a buffer and position the cursor
at the appropriate line.
Apple rulez, so does Unix, so does emacs