why is zsh globbing not working with find command? why is zsh globbing not working with find command? unix unix

why is zsh globbing not working with find command?


find . -name *mobile* # does not work

vs

find . -name '*mobile*' # works

The difference is due to the steps that the shell takes when it parses a line. Normally, the shell expands any wildcards it finds before it runs the command. However, single quotes marks the argument as being a literal, which means that the shell does not preform wildcard expansion on that argument before running the command.

To demonstrate the difference, suppose you are in a directory with the following files:

$ tree./mobile.1dir/    mobile.2

zsh will expand the first form to the following before running it:

find . -name mobile.1

Which means that find will only look for files named literally mobile.1

The second form will be run as follows:

find . -name *mobile*

Which means that find will look for any filename containing the string "mobile".

The important thing to note here is that both zsh and find support the same wildcard syntax, but you want find to handle the wildcards in this case, not zsh.


Turns out that all you have to do to solve the problem is add some quotes around the input:

find . -name '*mobile*'

I don't really have an answer as to why just yet...and the documentation doesn't have an something that sticks out to me, but let me know if you know the answer!