【问题标题】:find command: list every directory and subdir, except .git or .hg dir and subdirsfind 命令:列出每个目录和子目录,除了 .git 或 .hg 目录和子目录
【发布时间】:2012-12-25 15:24:38
【问题描述】:

我尝试在我的工作目录中使用此命令

find . -type d  \( ! -name .git  -prune \) -o \( ! -name .hg  -prune \)

好像没用?

删除 prune 只会排除 .git.hg 目录,而不是它们的子目录

【问题讨论】:

  • @pktangyue 不幸的是我没有权限安装tree
  • 为什么需要权限?您可以将其安装在您的主目录中。

标签: bash command find subdirectory


【解决方案1】:
find . \( -name .git -o -name .hg \) -prune -o -type d -print

【讨论】:

    【解决方案2】:

    我的回答与@Barmar 的回答基本相同,我对此表示赞同:

    find . \( -name .git -o -name .hg \) -prune -o \( -type d -print \)

    关于这个命令的一点解释可能对你有帮助:

    这里-o 表示OR。当find 找到与.git.hg 匹配的文件名时,由于-prune 选项而停止进一步搜索并评估为true,因此跳过另一个-o 分支(即目录打印)。这就是为什么只有那些不包含.git.hg 的目录才会出现。

    您也可以在 SO 上参考这个问题:How to use '-prune' option of 'find' in sh?

    【讨论】:

      猜你喜欢
      • 2014-06-13
      • 2015-07-16
      • 2023-04-02
      • 2011-02-23
      • 2017-11-16
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 2012-09-02
      相关资源
      最近更新 更多