Unix 'find' without descending into matched directories

 ̄綄美尐妖づ 提交于 2019-12-13 03:48:48

问题


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

回答1:


Use -depth:

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

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



来源:https://stackoverflow.com/questions/24930778/unix-find-without-descending-into-matched-directories

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!