Re: best way to find and delete (may contains directories)

Bernhard Voelker <[email protected]>
Newsgroups gmane.comp.gnu.findutils.bugs
Message-ID <[email protected]>
On 3/27/21 10:16 PM, James Youngman wrote:
>  Personally, I would probably use -delete to avoid the overhead of -exec
> entirely (the explicit -depth is essentially only there for documentation):
> 
> find . -depth \( -path '*0/*' -o -path '*0' \) -delete
__________________________^^______________^^

Just to clarify further: the above pattern for -path is not the same
as specifying '-name 0', because it would match any file or directory
which ends on "0", like e.g. "dir0".

The following is therefore closer to the original (yet still avoiding
to spawn a separate process):

  find . -depth \( -path '*/0/*' -o -path '*/0' \) -delete
or
  find . -depth \( -path '*/0/*' -o -name 0 \) -delete

As James mentioned, explicitly specifying -depth is not necessary as it
is implied by -delete, still it comes handy when you first want to have
a look which files would be deleted by exchanging -delete by -print;
it would still enforce the depth-first method:

  find . -depth \( -path '*/0/*' -o -name 0 \) -print

Have a nice day,
Berny
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.