Date: 06 Nov 2002 14:38:40 -0500 From: "Alex(ander Sendzimir)" <alex@battleface.com> To: freebsd-questions@FreeBSD.ORG Subject: Re: simple find command Message-ID: <1036611521.309.20.camel@prometheus> In-Reply-To: <200211061124.25334.mbettinger@championelevators.com> References: <200211061124.25334.mbettinger@championelevators.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1036611521.309.20.camel>