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

"Weatherby,Gerard" <[email protected]>
Newsgroups gmane.comp.gnu.findutils.bugs
Message-ID <f040f291-efd1-40fc-a727-a436316b5296@Spark>
find. -name 0 -exec rm -fr {} \;

--
Gerard Weatherby | Application Architect
NMRbox | Department of Molecular Biology and Biophysics | UConn Health
263 Farmington Avenue, Farmington, CT 06030-6406
uchc.edu<http://uchc.edu>
On Mar 26, 2021, 9:58 PM -0400, Peng Yu <[email protected]>, wrote:
*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

Hi,

If just find is used, the following error will be printed. There are
many ways to solve this problem.

$ mkdir -p {x..z}/0/
$ touch {x..z}/0/1.txt
$ find -name 0 -delete
find: cannot delete ‘./z/0’: Directory not empty
find: cannot delete ‘./x/0’: Directory not empty
find: cannot delete ‘./y/0’: Directory not empty

Assuming no directories to be deleted are in other, I come up with
this. Is this the best way (in terms of
robustness/readability/performance) to solve this problem?

$ find -name 0 -printf '%p\0' | xargs -r -0 rm -rf

--
Regards,
Peng
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.