bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: James Youngman
Subject: Re: best way to find and delete (may contains directories)
Date: Sat, 27 Mar 2021 21:16:48 +0000

On Sat, Mar 27, 2021 at 5:50 PM Weatherby,Gerard <gweatherby@uchc.edu>
wrote:

> find. -name 0 -exec rm -fr {} \;


-exec rm is very likely a better choice in a lot of ways than xargs here,
but using -exec .... {} \; introduces a lot of overhead because it only
processes one file at a time.     This would be substantially more
efficient:

find. -name 0 -exec rm -fr -- {} \+



The "--" is probably superfluous in this case but it is generally good
practice.  It's there in case the rm command likes (like GNU rm) to
recognize options which come after arguments.   This is an example of this
in action:

$ rm -fr */0/1.txt -i
rm: remove regular empty file 'x/0/1.txt'? n
rm: remove regular empty file 'y/0/1.txt'? n
rm: remove regular empty file 'z/0/1.txt'? n

 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

James.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]