I need to print the directory structure of our production system and I would like to remove some specific directories from the tree?

How do we specify multiple ignore patterns for tree command?

2 Answers 2


You simply provide all the patterns to the -I command, separated by |. From the manpage:

-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.

So, for example

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

skips the 'docs', 'bin', and 'lib', directories, and any directory with 'test' in the name, wherever they may lie within the directory hierarchy. Obviously, you can apply wildcards for much more powerful matching.

  • 6
    Looked at the man page, saw a very terse explanation for "-I", was frustrated. Didn't think to look a few lines above. Thanks. ;) Nov 13, 2014 at 9:47
  • How to set filter to get .html files only, nothing else Sep 4, 2015 at 10:23
  • Thanks! I use this to browse my code from the command line with excluding node_modules. Mar 15, 2017 at 15:43
  • 6
    How can a subdirectory such as docs/subdoc/ be excluded? Dec 25, 2017 at 12:39
  • 3
    @JitendraVyas: how about tree --prune -P '*.html' You will also get directories, but only those with .html files in them.
    – fbicknel
    Aug 22, 2018 at 14:57

This answer does not specifically answer the question, however a common reason for doing operations like this is to ignore things that git ignores.

Tree has added a --gitignore flag as of tree Version 2.0.0 (12/21/2021).

If you have a version of tree older than this and you have ripgrep installed you could create an alias like this to achieve something similar.

alias itree='rg --files | tree --fromfile'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .