[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: best way to find and delete (may contains directories)
From: |
Bernhard Voelker |
Subject: |
Re: best way to find and delete (may contains directories) |
Date: |
Sun, 28 Mar 2021 11:31:22 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 |
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