刪除所有子目錄中符合的目錄

刪除所有子目錄中符合的目錄

如何刪除run-*.achillesLinux 下所有子目錄中的所有目錄?

我嘗試過find /path -name run-*.achilles -type f -delete,但沒有成功。

答案1

這裡有幾個問題:

  1. 您應該引用*以防止 shell 通配符。
  2. -type f告訴find你想要文件。
  3. find -delete不會刪除非空目錄。看到這個問題。從那裡的答案之一調整解決方案:

    find /path -path '*/run-*.achilles/*' -delete
    find /path -type d -name 'run-*.achilles' -empty -delete
    

它並不完美,第一行會匹配.../run-a/b.achilles/...。我認為。這個指令應該要匹配得更好:

find /path -type d -name 'run-*.achilles' -exec rm -rf {} +

它使用rm -rf,所以要小心。

相關內容