小编Gab*_*mbe的帖子

使用 Unix 的 find 命令查找匹配名称的目录但不查找具有相同名称的子目录

编辑:我错误地歪曲了我的问题。一个更准确的例子现在出现在下面。

我想递归遍历目标目录中的所有目录,并在找到第一个 .git 目录后停止每个递归调用。

例如,如果我们有这些路径:

/home/code/twitter/.git/
/home/code/twitter/some_file
/home/code/twitter/some_other_file 
/home/code/facebook/.git/
/home/code/facebook/another_file
/home/code/configs/.git/
/home/code/configs/some_module/.git/
/home/code/configs/another_module/.git/
/home/code/some/unknown/depth/until/this/git/dir/.git/
/home/code/some/unknown/depth/until/this/git/dir/some_file
Run Code Online (Sandbox Code Playgroud)

我只想要结果中的这些行:

/home/code/twitter
/home/code/facebook
/home/code/configs
/home/code/some/unknown/depth/until/this/git/dir/
Run Code Online (Sandbox Code Playgroud)

-maxdepth这里对我没有帮助,因为我不知道我的目标的每个子目录的第一个 .git 目录有多深。

我以为find /home/code -type d -name .git -prune会这样做,但它对我不起作用。我错过了什么?

linux unix command-line find

11
推荐指数
2
解决办法
1万
查看次数

标签 统计

command-line ×1

find ×1

linux ×1

unix ×1