tree command failing strangely with some patterns

I have the following directory:

❯ tree -p
.
└── [drwxr-xr-x]  dir
    ├── [-rw-r--r--]  a.ml
    ├── [-rw-r--r--]  a.o
    ├── [-rw-r--r--]  b.ml
    └── [-rw-r--r--]  b.o

If I try to filter tree can’t find anything:

❯ tree -p -P *.ml
zsh: no matches found: *.ml
❯ tree -p -P *ml
zsh: no matches found: *ml

And if I go in the directory dir:

❯ tree -p -P *.ml
b.ml [error opening dir]

0 directories, 0 files
❯ tree -p -P *ml
b.ml [error opening dir]

0 directories, 0 files

Am I not seeing something obvious here? Why does it fail and how can I fix it?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

You need to quote your pattern, otherwise it will be interpreted by the shell instead of tree.

This should work fine:

tree -p -P '*.ml'

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply