From owner-freebsd-questions Wed Nov 6 9:50:16 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2E77737B401 for ; Wed, 6 Nov 2002 09:50:15 -0800 (PST) Received: from smtp.infracaninophile.co.uk (smtp.infracaninophile.co.uk [81.2.69.218]) by mx1.FreeBSD.org (Postfix) with ESMTP id 68AB043E7B for ; Wed, 6 Nov 2002 09:50:13 -0800 (PST) (envelope-from m.seaman@infracaninophile.co.uk) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost.infracaninophile.co.uk [IPv6:::1]) by smtp.infracaninophile.co.uk (8.12.6/8.12.6) with ESMTP id gA6Ho2MO025832 for ; Wed, 6 Nov 2002 17:50:02 GMT (envelope-from matthew@happy-idiot-talk.infracaninophile.co.uk) Received: (from matthew@localhost) by happy-idiot-talk.infracaninophile.co.uk (8.12.6/8.12.6/Submit) id gA6HnvXX025827 for freebsd-questions@FreeBSD.ORG; Wed, 6 Nov 2002 17:49:57 GMT Date: Wed, 6 Nov 2002 17:49:57 +0000 From: Matthew Seaman To: freebsd-questions@FreeBSD.ORG Subject: Re: simple find command Message-ID: <20021106174957.GA25190@happy-idiot-talk.infracaninophi> Mail-Followup-To: Matthew Seaman , freebsd-questions@FreeBSD.ORG References: <200211061124.25334.mbettinger@championelevators.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200211061124.25334.mbettinger@championelevators.com> User-Agent: Mutt/1.5.1i X-Spam-Status: No, hits=-10.6 required=5.0 tests=IN_REP_TO,REFERENCES,SPAM_PHRASE_01_02,USER_AGENT, USER_AGENT_MUTT version=2.41 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 On Wed, Nov 06, 2002 at 11:24:19AM -0600, Matthew Bettinger wrote: > Hello, > > I am having a bit of trouble with the find command. I am a novice in its use > so maybe someone can help me out here. > > I have a list of files (hundreds) in directory . and need to search through > and delete every file that contains the word foo. > > Some of my failed attemps... > > find . -exec grep -i "foo" -ok -delete {} \; > > find . -exec grep -l 'foo' -ok -delete {}\; > > find . -exec grep "foo" {}\; | xargs rm find . -type f -print | xargs grep -l foo | xargs rm or if you have file names with spaces or other characters syntactically significant to the shell: find . -type f -print0 | xargs -0 grep -l --null foo | xargs -0 rm Cheers, Matthew -- Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks Savill Way Marlow Tel: +44 1628 476614 Bucks., SL7 1TH UK To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message