Unix“查找”而不下降到匹配的目录 [英] Unix 'find' without descending into matched directories

查看:273
本文介绍了Unix“查找”而不下降到匹配的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  find。我试图从存储库中删除所有的git文件。 -name.git *-exec rm -rf {} \; 

然而, rm 警告文件不能被删除(因为他们的父目录已被删除)。

有没有办法让 find 停止当它发现一个匹配的目录时递归?



例如 find ...

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

...产品

  /。gitmodules 
/.git


解决方案

使用 -depth

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

这将允许您在其父目录之前先处理文件或子目录。 b $ b

I was trying to remove all git files from a repository with this:

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

However, rm warns that files could not be deleted (because their parent directory has already been deleted).

Is there a way to get find to stop recursing when it finds a matching directory?

E.g. find...

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

... produces

/.gitmodules
/.git

解决方案

Use -depth:

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

This would allow you to process the files or subdirectories first before their parent directories.

这篇关于Unix“查找”而不下降到匹配的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆