[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
best way to find and delete (may contains directories)
From: |
Peng Yu |
Subject: |
best way to find and delete (may contains directories) |
Date: |
Fri, 26 Mar 2021 20:58:02 -0500 |
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
- best way to find and delete (may contains directories),
Peng Yu <=