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: Jay Jacobson
Date:  
To: plug-discuss
Subject: Re: use find to search contents of files in /etc
On Fri, 12 Mar 2004, Kurt Granroth 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.

[snip]
> > 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.



Why not just use grep by itself? No need for 'find' at all. If you want to
search just the files, omitting directories:

grep -d skip hostname /etc/*

If you want to recursively search all the files:

grep -r hostname /etc/*

~Jay

--
..
.. Jay Jacobson
.. Edgeos, Inc. - 480.961.5996 - http://www.edgeos.com
..
.. Managed Vulnerability Assessment
.. Services for Information Security Professionals
..

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