[NTLUG:Discuss] Re: Renaming a Linux host

Robert Thompson ntlug at thorshammer.org
Thu Jul 28 20:01:13 CDT 2005


 > find /path -type f | xargs grep "foo"

I've had that command puke and die because the arg list to grep was too 
long. A better version is:

find /path -type f -exec grep "foo" {} \;

The -exec flag executes the following command once for each match found. 
The "following command" is terminated by a ;, so you have to escape the 
; from the shell so find will see it. The string {} is replaced by the 
thing that was found. Also specifically grepping something out of a 
file, I'll use the -l option to grep to just list the files that 
matched. I'll then grep/edit the interesting sounding files that it 
finds. This prevents matches from spewing across your screen faster than 
you can read them.

=-= Robert Thompson


Thomas Cameron wrote:

> On Sun, 2005-07-24 at 23:15 -0500, Leroy Tennison wrote:
> 
> 
>>I was afraid someone was going to say something to that effect, it never 
>>seems to be that easy.  BTW, I'm running into problems with 'grep -R 
>><hostname> *' on Red hat 9.  It never seemed to complete (waited an hour 
>>on a 1.7GHz host with a 40GB HD which is 73% full).  I then decided to 
>>get a little omre sophisticated and do (at /)
>>
>>for i in `ll | grep ^d | awk '$0 ~ "dev" {next}; $0 ~ "proc" {next}; 
>>{print $NF}'`; do grep -R <hostname> $i; done
>>
>>but grep still ran out of resources in /var.  Any ideas or, by the time 
>>I get to /var, do I care?
> 
> 
> To change the hostname, edit /etc/hosts and /etc/sysconfig/network.
> 
> To grep for a string in all the files under a directory, I usually use
> 
> find /path -type f | xargs grep "foo"
> 
> where "path" is the directory I want to search, and "foo" is the string
> I am looking for.  It typically works for me.
> 




More information about the Discuss mailing list