From owner-freebsd-questions Wed Nov 6 12:29:57 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 8710337B401 for ; Wed, 6 Nov 2002 12:29:54 -0800 (PST) Received: from smtprelay9.dc2.adelphia.net (smtprelay9.dc2.adelphia.net [64.8.50.53]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1C55643E3B for ; Wed, 6 Nov 2002 12:29:48 -0800 (PST) (envelope-from alex@battleface.com) Received: from prometheus.localdomain ([68.64.68.238]) by smtprelay9.dc2.adelphia.net (Netscape Messaging Server 4.15) with ESMTP id H568XG03.09A for ; Wed, 6 Nov 2002 15:29:40 -0500 Subject: Re: simple find command From: "Alex(ander Sendzimir)" To: freebsd-questions@FreeBSD.ORG In-Reply-To: <200211061124.25334.mbettinger@championelevators.com> References: <200211061124.25334.mbettinger@championelevators.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 06 Nov 2002 14:38:40 -0500 Message-Id: <1036611521.309.20.camel@prometheus> Mime-Version: 1.0 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 Matt, It's unclear from your post whether you mean to find files that *contain* "foo" or files where "foo" is in the filename. Here are the two scenarios acted out. [1] Remove files that contain "foo". cd directory/where/files/reside grep -r -i foo ./* cd'ing into where the files are is not strictly necessary. I like to do this for safety reasons if I mistype. Otherwise you may place the directory at the end of the grep command line as grep -r -i foo /directory/where/files/reside Do the resultant files meet your expectations? Check this before deleting them. It might be safer to move them to a holding directory first. Then delete them when you're beyond any quivering feelings of doubt. grep -r -i foo ./* | xargs rm -v I'm assuming there might be subdirectories where the files are. If not or you don't want to get into them, then remove "-r" in the grep command. [2] Remove files that have "foo" in their filename. find /directory/where/files/reside -name "*foo*" -print \ -exec rm {} \; Again, the caveat about checking your results before deleting is repeated here. The slash at the end of the line above (after -print) is because the line is too long in this email. This is the shell escape for line continuation. You can experiment with it. Perhaps this clears up some of the other posts. Alex On Wed, 2002-11-06 at 12:24, Matthew Bettinger wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 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 Thanks for any help. Matt -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (FreeBSD) iD8DBQE9yVBIXG7+MmNwciURAr1VAKCJWZF87EfqAk8hLdnj/prlZwpVDwCbBrAt Lq+3Zv2Ocd4EmxAXfdhp1OY= =HNAV -----END PGP SIGNATURE----- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message -- A L E X A N D E R S E N D Z I M I R Battleface Computing Custom Computing - Linux & Free BSD - C, Perl, Python, WWW info@battleface.com | 802 863 5502 | Colchester, VT 05446 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message