【问题标题】:Unix 'find' without descending into matched directoriesUnix 'find' 不下降到匹配的目录
【发布时间】:2014-07-24 18:23:34
【问题描述】:

我试图从存储库中删除所有 git 文件:

find . -name ".git*" -exec rm -rf {} \;

但是,rm 警告说文件不能被删除(因为它们的父目录已经被删除了)。

有没有办法让find 在找到匹配目录时停止递归?

例如find...

/.gitmodules
/.git/stuff
/.git/.gitfile

...产生

/.gitmodules
/.git

【问题讨论】:

标签: unix find


【解决方案1】:

使用-depth:

find . -depth -name ".git*" -exec rm -rf {} \;

这将允许您先处理文件或子目录,然后再处理它们的父目录。

【讨论】:

    猜你喜欢
    • 2013-04-24
    • 2021-06-24
    • 1970-01-01
    • 2018-06-08
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 1970-01-01
    相关资源
    最近更新 更多