我们如何为 `tree` 命令指定多个忽略模式?

Bha*_*nha 133 command-line patterns tree

我需要打印我们生产系统的目录结构,我想从树中删除一些特定的目录?

我们如何为tree命令指定多个忽略模式?

ire*_*ses 187

您只需向-I命令提供所有模式,以|. 从联机帮助页:

-P pattern
      List  only  those files that match the wild-card pattern.  Note:
      you must use the -a option to also consider those  files  begin?
      ning  with a dot `.' for matching.  Valid wildcard operators are
      `*' (any zero or more characters), `?' (any  single  character),
      `[...]'  (any single character listed between brackets (optional
      - (dash) for character  range  may  be  used:  ex:  [A-Z]),  and
      `[^...]'  (any  single character not listed in brackets) and `|'
      separates alternate patterns.

-I pattern
      Do not list those files that match the wild-card pattern.
Run Code Online (Sandbox Code Playgroud)

所以,例如

tree -I 'test*|docs|bin|lib'
Run Code Online (Sandbox Code Playgroud)

跳过“docs”、“bin”和“lib”目录以及名称中带有“test”的任何目录,无论它们位于目录层次结构中的何处。显然,您可以应用通配符来实现更强大的匹配。

  • 看了手册页,看到“-I”的一个非常简洁的解释,很沮丧。没想到看上面几行。谢谢。;) (6认同)
  • 如何排除诸如“docs/subdoc/”之类的子目录? (4认同)
  • @JitendraVyas:```tree --prune -P '*.html'``` 你也会得到目录,但只有那些包含 ```.html``` 文件的目录。 (2认同)