grep

Doug Gwyn gwyn at smoke.BRL.MIL
Wed Oct 24 06:15:09 AEST 1990


In article <1990Oct23.123025.18012 at kodak.kodak.com> tiefel at sunshine.Kodak.COM (Lenny Tiefel) writes:
>I have a main directory with hundreds of subdirectories, 
>and I want to find a file with a particular string, say "xyz"
>The grep command only works in one directory at a time. Is there
>a way of searching my whole directory structure to find a file
>with a particular string?

"grep" doesn't grok directories at all.
However, UNIX is a toolkit environment.  Whenever you want to execute
a command on all files, or some readily selected subset of files,
within a directory hierarchy, you should think of "find" and "xargs".
(If you don't have "xargs", complain to your vendor.)

	find root_name -type f -print | xargs grep pattern /dev/null

The extra argument to "grep" is to ensure that the filename will be
printed for each matching line.  (Workaround for a wart in "grep"'s
design.)



More information about the Comp.unix.questions mailing list