Re: use find to search contents of files in /etc

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Kurt Granroth
Date:  
To: plug-discuss
Subject: Re: use find to search contents of files in /etc
On Mar 11, 2004, at 12:30 PM, Jeremy C. Reed wrote:
> On Thu, 11 Mar 2004 wrote:
>
>> I want to search all files in /etc that have the word hostname in
>> them.
>> I do not want to search the actual file name for hostname but instead
>> I
>> want to search the content of the files for the word hostname.
>
> find /etc -exec grep hostname "{}" \;
>
> Or:
>
> find /etc -type f | xargs grep hostname


I've gotten into the habit of using this lately:

find /etc -type f -print0 | xargs -0 grep hostname

This is because there are a number of directories and files off of /etc
that have spaces in them. The -print0/-0 combination will allow
searching them without causing pages of spurious errors. Since it can
only help and never hurt, I have taken to using them always.

---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss