grep

Max Heffler max at lgc.com
Wed Oct 24 00:32:47 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?
>
Try this:

	cd x		where x is head of tree to search
	find . -type f -exec grep xyz {} /dev/null \; | tee $HOME/xyz.out

The cd is done separately because I have had problems with symbolic links
on some machines.  This will search files only (type -f) and if your grep
supports a caseless option (grep -i) you might want to use it, in some cases.
The /dev/null is to cause grep to report back the filenames where the string
is found, since grep will not report the filename for a single argument.
Finally, the tee allows you to monitor progress, as well as have a file to
reference later.

--
Max Heffler			internet: max at lgc.com
Landmark Graphics Corp.		uucp: ..!uunet!lgc!max
333 Cypress Run, Suite 100      phone: (713) 579-4751
Houston, Texas  77094



More information about the Comp.unix.questions mailing list