Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!lgc.com!max From: max@lgc.com (Max Heffler) Newsgroups: comp.unix.questions Subject: Re: grep Summary: How to do a tree grep Keywords: Use find Message-ID: <1990Oct23.143247.5639@lgc.com> Date: 23 Oct 90 14:32:47 GMT References: <1990Oct23.123025.18012@kodak.kodak.com> Sender: news@lgc.com Organization: Landmark Graphics Corp., Houston, Tx Lines: 25 Nntp-Posting-Host: maxsun.lgc.com In article <1990Oct23.123025.18012@kodak.kodak.com> tiefel@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@lgc.com Landmark Graphics Corp. uucp: ..!uunet!lgc!max 333 Cypress Run, Suite 100 phone: (713) 579-4751 Houston, Texas 77094