我是一名Linux用户,有一个包含许多子目录的文件夹。我需要删除所有具有相同名称的子目录。例如,
dir
|---subdir1
|---subdir2
| |-----subdir1
|---file
我想要删除全部的subdir1
目录。以下是我的脚本:
find dir -type d -name "subdir1" | while read directory ; do
rm -rf $directory
done
然而,我执行了它,但似乎什么也没有发生。
我还尝试过 find dir -type d "subdir1" -delete
,但仍然没有任何反应。
find dir -type d -name "subdir1"
能正确地列出文件夹吗? - Inianrm -rf dir/subdir1
来删除其中一个,并且它有效。我不需要执行sudo
。 - Yves