I just installed tree with brew, and when I try to run it like this (on a python project folder):
tree -I *.pyc
It returns [error opening dir] for the pyc files, for example:
I get this running ls:
a.pyc b.pyc
and when I run tree -I *.pyc, I get:
b.pyc [error opening dir]
0 directories, 0 files
Any ideas why?
This is not a problem with tree, it is the shell (bash) doing it's filename expansions - also known as globbing. So what is passed into tree is a list of all the file names in the current directory ending in .pyc. Only the first filename will follow the -I option (a.pyc), the others will be seen as directory names.
tree wants to do it's own globbing (find is the same) so you must protect it from the shell by adding quotes:
tree -I '*.pyc'
The quotes will be stripped off by the shell and will not be seen by tree, it will just see *.pyc.
In this case either single or double quotes would do the trick, but probably safer to stick with single quotes since other expansions are done inside double quotes.
BTW, when you get this kind of issue use:
set -x
that will show the command after bash expansions. Use set +x to switch it off. These can be used on the command-line or in a script for debugging.
Surround the wildcard patterns passed to -I and -P with quotes to avoid globbing:
tree -I '*.pyc'
From man tree:
Valid wildcard operators are
'*'(any zero or more characters)
'?'(any single character)
'[...]'(any single character listed between brackets)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With