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


105

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

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

Answers:


141

您只需为-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.

因此,例如

tree -I 'test*|docs|bin|lib'

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


4
看着手册页,看到对“ -I”非常简洁的解释,感到沮丧。没想到要看上面几行。谢谢。;)
Tomislav Nakic-Alfirevic

如何将过滤器设置为仅获取.html文件,仅此而已
Jitendra Vyas

谢谢!我使用它从命令行浏览我的代码,但不包含node_modules。
thevangelist'Mar

2
如何docs/subdoc/排除子目录?
user1032531

@JitendraVyas:怎么样,tree --prune -P '*.html'您也将获得目录,但是只有其中包含.html文件的目录。
fbicknel
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.