Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!akbloom From: akbloom@aplcen.apl.jhu.edu (Keith Bloom) Newsgroups: comp.unix.questions Subject: Re: grep Keywords: grep, recursive Message-ID: <1991Apr15.042100.11727@aplcen.apl.jhu.edu> Date: 15 Apr 91 04:21:00 GMT References: <1991Apr14.214414.9815@hellgate.utah.edu> Organization: The Johns Hopkins University Lines: 26 mmoore%hellgate.utah.edu@cs.utah.edu (Michael Moore) writes: > Does anyone know if there is an easy way to recursively search for a >pattern down the entire file tree of a directory? If your system has xargs, you could try: find . -name '*' -print | xargs grep pattern If you have a huge directory tree with thousands of files in it, this may not work. If you don't have xargs, there's: find . -name '*' -print -exec grep pattern {} \; but this is more cumbersome, because it will print the names of all your files, whether they contain the pattern or not. (I assume you want to know the name of the file that 'pattern' is in.) In general, 'find' is usually your best bet for recursive operations like the one you have in mind. (PS: both methods work as stated under Ultrix. They ought to work the same on any reasonable Unix system, but there's no guarantee.)