linux - shell find -delete -- 如何避免删除自身

标签 linux bash shell

root
  -- level-1-folder-1-dynamic
  -- level-1-folder-2-dynamic-maybe-empty
  -- level-1-folder-3-dynamic
     -- level-2-folder-dynamic-need-to-be-deleted
     -- level-2-folder-dynamic-need-to-be-deleted
        -- file-1
        -- file-2

我想使用find命令删除所有30分钟前创建的二级文件夹,但我找不到所有二级文件夹并删除它们。
我现在能做的就是找到所有文件并删除它们,但二级文件夹仍然存在
find root -type -f -cmin +30 -delete
如果我使用 find root -type -d -empty -delete,它将删除所有空文件夹,包括 level-1 和 root 本身。

如何删除所有二级文件夹?
谢谢

最佳答案

要仅删除 2 级或更深级别的那些空目录,请使用 -mindepth 2:

find root -mindepth 2 -type d -empty -delete

关于linux - shell find -delete -- 如何避免删除自身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36928504/

相关文章:

php - strpos 未返回正确的结果

linux - 在 Windows 中字体显示为斜体,但在 Linux 中它始终显示为粗体

linux - 为列表中的每个项目执行 bash 脚本

linux - 使用定界符在 BASH 中拆分大文件

bash - 如果 errexit 打开,我如何运行可能会失败的命令并获取其退出代码?

android - 在 adb shell 上运行 linux bash 脚本

linux - Crontab 以不同的方式运行 bash

linux - 汇编中系统调用的返回值是什么?

linux - 一个是什么意思!在shell中的命令之前?

linux - 在 shell 脚本中从文件中提取特定模式