Skip site navigation (1)Skip section navigation (2)
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

--AhhlLboLdkugWU4S
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Nov 06, 2002 at 11:24:19AM -0600 Matthew Bettinger <mbettinger@cham=
pionelevators.com> wrote:
> Hello,
>=20
> I am having a bit of trouble with the find command.  I am a novice in its=
 use=20
> so maybe someone can help  me out here.=20
>=20
> I have a list of files (hundreds) in directory . and need to search throu=
gh=20
> and delete every file that contains the word foo.
>=20
> Some of my failed attemps...
>=20
> find . -exec grep -i "foo" -ok -delete {} \;
>=20
> find . -exec grep -l 'foo' -ok -delete {}\;
>=20
> 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.=20

--=20
David S. Jackson                        dsj@dsj.net
=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D=
-=3D-=3D-=3D-=3D-=3D-=3D-=3D
I think we're all Bozos on this bus.
		-- Firesign Theatre

--AhhlLboLdkugWU4S
Content-Type: application/pgp-signature
Content-Disposition: inline

-----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-----

--AhhlLboLdkugWU4S--

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?20021111180312.C20887>