I want to use tree to only show files that match a specific file name. E.g. filename.
The man page says:
-P pattern List only those files that match the wild-card pattern. Note: you must use the -a option to also consider those files beginning 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.
However, I don’t want to show directories that don’t contain that file.
tree . -P filename --prune
(if you don’t have
brew install tree)
and if you want to match on directories too then use:
tree . -P *match string* --matchdirs --prune
Making this an alias:
`alias treefind=”tree . –prune –matchdirs -P”` so you can use it like this:
and if you’re wanting to use a regex then: