Date: Mon, 11 Nov 2002 18:03:12 -0500 From: "David S. Jackson" <deepbsd@earthlink.net> To: Matthew Bettinger <mbettinger@championelevators.com> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: simple find command Message-ID: <20021111180312.C20887@sylvester.dsj.net> In-Reply-To: <200211061124.25334.mbettinger@championelevators.com>; from mbettinger@championelevators.com on Wed, Nov 06, 2002 at 11:24:19AM -0600 References: <200211061124.25334.mbettinger@championelevators.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On Wed, Nov 06, 2002 at 11:24:19AM -0600 Matthew Bettinger <mbettinger@championelevators.com> 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
well, you've gotten some fine find advice, so I'll just suggest
that you don't have to use find:
bash]$ grep -H foo * | cut -d: -f1 | while read file; do
> echo deleting $file && rm $file
> done
You've already seen how to do it with xargs; this is just another
possibility that happens to work even when the filename has
metacharacters in it.
--
David S. Jackson dsj@dsj.net
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
I think we're all Bozos on this bus.
-- Firesign Theatre
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE90DcwlcISCqozZ4YRApYGAKCTw5JkyPX2Ot5Guug8E7v8TLITigCgulKX
I6HfkBB6aBoY37Jt0+8oADw=
=8Ey0
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021111180312.C20887>
