Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.unix.questions Subject: Re: grep Message-ID: <14225@smoke.BRL.MIL> Date: 23 Oct 90 20:15:09 GMT References: <1990Oct23.123025.18012@kodak.kodak.com> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 18 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? "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.)