Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

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.

share|improve this answer
    
+1. Thanks. It worked. –  SiB Sep 11 '12 at 10:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.