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 Friday 12 March 2004 08:43 am, Jay Jacobson wrote:
> On Fri, 12 Mar 2004, Kurt Granroth wrote:
> > 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/*


Habit, I guess. The find solution is pretty much guaranteed to work
everywhere and I've used it for years and years. I've never heard of or seen
anybody use grep by itself in this way before this thread. It would be
interesting to see if this works on all *nix systems or just on those with
GNU tools installed. I would also be curious to see when those options were
added. If it was a long time ago, then it is odd that I hadn't heard of them
before.

Kurt

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