From owner-freebsd-questions Wed Nov 6 9:47:48 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 7293B37B401 for ; Wed, 6 Nov 2002 09:47:47 -0800 (PST) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id F237243E91 for ; Wed, 6 Nov 2002 09:47:46 -0800 (PST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.6/8.12.6) id gA6HljtD059242; Wed, 6 Nov 2002 11:47:45 -0600 (CST) (envelope-from dan) Date: Wed, 6 Nov 2002 11:47:45 -0600 From: Dan Nelson To: Matthew Bettinger Cc: freebsd-questions@FreeBSD.ORG Subject: Re: simple find command Message-ID: <20021106174745.GA96511@dan.emsphone.com> 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> X-OS: FreeBSD 5.0-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.1i 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 In the last episode (Nov 06), Matthew Bettinger said: > 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 How about something like find . -type f | xargs grep -l foo | xargs rm which will pipe a list of all files into "xargs grep", which will then output only the filenames that have foo in them, which gets piped into "xargs rm" which removes them. -- Dan Nelson dnelson@allantgroup.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message