[96381] in RedHat Linux List

home help back first fref pref prev next nref lref last post

Re: Newbie: Searching sub directories for text

daemon@ATHENA.MIT.EDU (David E. Fox)
Mon Oct 26 18:45:17 1998

From: "David E. Fox" <dfox@belvdere.vip.best.com>
Reply-To: dfox@belvdere.vip.best.com
To: redhat-list@redhat.com
Date: Mon, 26 Oct 1998 15:40:38 -0800
Resent-From: redhat-list@redhat.com

On Mon, 26 Oct 1998, Dave wrote:

>How can I search a directory and all of its sub directories for a file
>containing a specified text string. I know how to use grep to search a
>single directory but is there a way to make it search all of the sub
>directories too? Maybe there is another program that I should be using??

Use 'grep' in conjuction with some other utility that generates the
names of the files you want to search. find(1) is ideal for this
purpose.

The easiest/simplest way I've found is to run the find in a subshell
of the grep line, e.g.:

cd /usr/src/linux
grep adaptec `find . -name *.[ch]`

This would find all *.c and *.h files underneath the Linux source
tree, and stick it on the command line automagically next to the
search term -- and grep ends up slogging through each file in 
turn.

Other ways to do it involve both find and grep, and potentially
xargs as well (useful if you have a large number of files to
look through.)

>Dave
--
------------------------------------------------------------------------
David E. Fox                 Tax              Thanks for letting me
dfox@belvdere.vip.best.com   the              change magnetic patterns
root@belvedere.sbay.org      churches         on your hard disk.
-----------------------------------------------------------------------


-- 
  PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
		http://www.redhat.com http://archive.redhat.com
         To unsubscribe: mail redhat-list-request@redhat.com with 
                       "unsubscribe" as the Subject.


home help back first fref pref prev next nref lref last post