如何删除具有特定名称的文件夹 [英] How to remove folders with a certain name
问题描述
在Linux中,如何删除嵌套在文件夹层次结构中的具有特定名称的文件夹?
In Linux, how do I remove folders with a certain name which are nested deep in a folder hierarchy?
以下路径在一个文件夹下,我想删除所有名为 a
的文件夹.
The following paths are under a folder and I would like to remove all folders named a
.
1/2/3/a
1/2/3/b
10/20/30/a
10/20/30/b
100/200/300/a
100/200/300/b
我应该在父文件夹中使用什么Linux命令?
What Linux command should I use from the parent folder?
推荐答案
如果目标目录为空,请使用find,仅对目录进行过滤,按名称进行过滤,执行rmdir:
If the target directory is empty, use find, filter with only directories, filter by name, execute rmdir:
find . -type d -name a -exec rmdir {} \;
如果要递归删除其内容,请将 -exec rmdir {} \;
替换为 -delete
或 -prune -exec rm -rf {}\;
.其他答案包括有关这些版本的详细信息,也请相信它们.
If you want to recursively delete its contents, replace -exec rmdir {} \;
with -delete
or -prune -exec rm -rf {} \;
. Other answers include details about these versions, credit them too.
这篇关于如何删除具有特定名称的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!