Skip site navigation (1)Skip section navigation (2)
Date:      06 Nov 2002 13:07:03 -0800
From:      swear@attbi.com (Gary W. Swearingen)
To:        mbettinger@championelevators.com
Cc:        <freebsd-questions@freebsd.org>
Subject:   Re: simple find command
Message-ID:  <3avg3ao1ag.g3a@localhost.localdomain>
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
Matthew Bettinger <mbettinger@championelevators.com> writes:

> I have a list of files (hundreds) in directory . and need to search through 
> and delete every file that contains the word foo.

Assuming that "directory" means "directory tree" and that "word" means
"string", this might work:

find . -type f -print0 | xargs -0 grep --null -l foo | xargs -0 rm -f

Test this or whatever you use thoroughly; such things are likely to
delete things you don't want deleted and/or not delete things you you
want deleted.  You're likely to want additional options on "rm", like
maybe "-P".  Use the man pages to know what you are doing and can do --
and test things well using test directories, etc.

If you really meant "word foo", then you've got a much tougher job,
starting with defining "word".  See the grep manual, at least.

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?3avg3ao1ag.g3a>