Devo stampare la struttura delle directory del nostro sistema di produzione e vorrei rimuovere alcune directory specifiche dall'albero?
Come specifichiamo più pattern di esclusione per tree
comando?
Risposta accettata:
Fornisci semplicemente tutti i modelli a -I
comando, separato da |
. Dalla 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.
Quindi, per esempio
tree -I 'test*|docs|bin|lib'
salta "docs", "bin" e "lib", le directory e qualsiasi directory con "test" nel nome, ovunque si trovino all'interno della gerarchia delle directory. Ovviamente, puoi applicare caratteri jolly per una corrispondenza molto più potente.