This works too:
find /dirname -exec grep -l 'whatever text' {} \;


-----Original Message-----
From:   Glynn Clements [SMTP:[EMAIL PROTECTED]]
Sent:   Wednesday, October 28, 1998 4:30 PM
To:     Dave
Cc:     [EMAIL PROTECTED]
Subject:        Re: Newbie: Searching sub directories for text


Dave wrote:

> How can I search a directory and all of its sub directories for a file
> containing a specified text string.

Use find and [f]grep.

> 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? 
> 
> I tried using Find along with Grep:
> 
>       find / -type f -print | xargs grep <string_to_search_for>

In general,

        find / -type f -print0 | xargs -0 grep <string_to_search_for>

is preferable, as it will cope with filenames which contain spaces.

> But I get the error message:
> 
>       grep: warning: /proc/kcore: operation not supported by device

Don't search /proc. You can use

        find / -path /proc -prune -o ...

to eliminate just /proc, or

        find / -mount ...

to prevent find from crossing filesystem boundaries.

> It trys to search files that grep can not deal with, generates error
> messages and fills the screen up with junk. Is there a way to limit the
> search to scripts, config files and source files?

Not easily. You would have to have to run `file' on each file that is
found, and only run grep if the output from file indicates that it is
suitable.

> Maybe there is another program that I should be using??

Not really. There isn't a `is this a text file' utility as such.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to