tree – only show files with matching file name but not directories that don’t contain the file

I want to use tree to only show files that match a specific file name. E.g. filename.

The man page says:

However, I don’t want to show¬† directories that don’t contain that file.

Here’s how:

tree . -P filename --prune

(if you don’t have tree¬†then: 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:

treefind some_file


and if you’re wanting to use a regex then:

treefind 'some_*'


Leave a Reply

Your email address will not be published. Required fields are marked *