From owner-freebsd-questions Thu Dec 27 16:28:26 2001 Delivered-To: freebsd-questions@freebsd.org Received: from blacklamb.mykitchentable.net (ekgr-dsl2-77.citlink.net [207.173.226.77]) by hub.freebsd.org (Postfix) with ESMTP id E91F937B405 for ; Thu, 27 Dec 2001 16:28:15 -0800 (PST) Received: from tagalong (unknown [165.107.42.196]) by blacklamb.mykitchentable.net (Postfix) with SMTP id 5080FEE692; Thu, 27 Dec 2001 16:30:35 -0800 (PST) Message-ID: <019901c18f36$89c8f8e0$c42a6ba5@lc.ca.gov> From: "Drew Tomlinson" To: Cc: References: <20011227172121.Q11529-100000@shumai.marcuscom.com> <014501c18f26$9d430970$c42a6ba5@lc.ca.gov> <3C2BB845.7070508@verizon.net> Subject: Re: How To Recursively Search Directory For Text String In Files? Date: Thu, 27 Dec 2001 16:28:14 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-Mimeole: Produced By Microsoft MimeOLE V6.00.2600.0000 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG ----- Original Message ----- From: "Simon Morton" To: "Drew Tomlinson" Cc: "Joe Clarke" ; Sent: Thursday, December 27, 2001 4:09 PM Subject: Re: How To Recursively Search Directory For Text String In Files? > That won't quite do it if you want only the names of matching files. > The following will do it for you without xargs: > > find -type f [-name {} \; > > which is almost the same as > > find -type f [-name {} > \; -print > > grep -l prints out just the name of any file containing the pattern. > grep -q prints nothing but returns 0 for matching files > > -exec is a conditional operator; if the command called by -exec returns > 0, -exec returns TRUE. This can be useful if you wanted an action > other than -print, say -delete for example. Thank you for your additional explanation. In this particular case it didn't matter it I got only the names of the files or the names plus the matches. But I can see where only the file names might be needed in some cases as in the -delete you mention. Thanks for your help, Drew > HTH > Simon > > Drew Tomlinson wrote: > > > >>> > >>You can do grep -r *, but I prefer: > >> > >>find -type f -name | xargs > >> > > grep > > > >> > >> > > > > Thank you very much! I *knew* it had to be possible but had not come > > across xargs yet. It looks like a very powerful tool that will have a > > lot of uses! > > > > Drew > > > > > >>For example: > >> > >>find /usr/ports -type f -name Makefile | xargs grep -i snmp > >> > >>This would search all Makefiles found anywhere in the /usr/ports tree > >> > > and > > > >>grep case-insensitvely through them for the pattern "snmp". > >> > >>Joe > >> > >> > >>>Thanks, > >>> > >>>Drew > >>> > >>> > >>>To Unsubscribe: send mail to majordomo@FreeBSD.org > >>>with "unsubscribe freebsd-questions" in the body of the message > >>> > >>> > >>> > >> > >>To Unsubscribe: send mail to majordomo@FreeBSD.org > >>with "unsubscribe freebsd-questions" in the body of the message > >> > >> > >> > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > > with "unsubscribe freebsd-questions" in the body of the message > > > > > > > > -- > http://www.SimonMorton.com > smorton at acm dot org > \rm -rf /bin/laden > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message