grep

Marten Terpstra a20 at nikhefh.nikhef.nl
Mon Apr 15 22:46:19 AEST 1991


mmoore%hellgate.utah.edu at 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?  

A recursive version of grep has been discussed several times on the net. One
of the solutions, and quite workable for me, is the following shell script :

-- Start of script --
#! /bin/sh
# Recgrep : a version of grep which recursively searches every directory and
# file starting in the current directory.
#
# Usage: recgrep pattern

if (test $# -lt 1) then
	echo "Usage: recgrep pattern"
else
	find . -type f -exec grep $1 {} /dev/null \;
fi
-- End of script --

This will start in your current directory and recursively walk down all
other dirs looking for you pattern.

I know there are many other variations, that may work even better, but this
one works just fine for me.

-Marten
--
Marten Terpstra                                  National Institute for Nuclear
Internet : terpstra at nikhef.nl 		                and High Energy Physics
Oldie-net: {....}mcsun!nikhefh!terpstra	      (NIKHEF-H), PO Box 41882, 1009 DB
Phone    : +31 20 592 5102                           Amsterdam, The Netherlands



More information about the Comp.unix.questions mailing list