查找标志:-exec rm -rf vs -delete

For*_*ker 7 bash directory find rm

我认为我在问题中提到的标志是相同的,但是我收到了前者的以下消息,但后者没有任何消息:

$ find . -mindepth 1 -type d -exec rm -rf {} \;
find: `./practice4': No such file or directory
find: `./practice10': No such file or directory
find: `./practice7': No such file or directory
find: `./practice9': No such file or directory
find: `./practice1': No such file or directory
find: `./practice5': No such file or directory
find: `./practice3': No such file or directory
find: `./practice6': No such file or directory
find: `./practice2': No such file or directory
find: `./practice8': No such file or directory
Run Code Online (Sandbox Code Playgroud)

我的额外问题是:是否有更简单的代码来删除所有子目录?删除顺序是随机的吗?我创建的目录使用

$ mkdir practice{1..10}
Run Code Online (Sandbox Code Playgroud)

Tho*_*hor 6

从 GNU 查找手册:

如果您的find' command removes directories, you may find that you get a spurious error message whenfind' 尝试递归到现在已删除的目录中。使用`-depth' 选项通常可以解决这个问题。

其他问题:

  • 命令的简单性取决于您的情况,在列出的情况下为:rm -rf practice*
  • IIRC,文件的处理顺序取决于文件系统。