[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: best way to find and delete (may contains directories)
From: |
Peng Yu |
Subject: |
Re: best way to find and delete (may contains directories) |
Date: |
Sun, 28 Mar 2021 09:38:50 -0500 |
On Sun, Mar 28, 2021 at 4:31 AM Bernhard Voelker
<mail@bernhard-voelker.de> wrote:
>
> 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
The above seems to be the best answer for the specific case of delete
directories found by -name 0. It avoids calling external programs.
> 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
It is also good to have this to check what is to be deleted beforehand.
--
Regards,
Peng