why is zsh globbing not working with find command?
Solution 1
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.1
dir/
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.
Solution 2
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!
Related videos on Youtube
ovatsug25
Currently (personal project): Developing full-stack Objective-C app. Objective-C / UIKit on iDevices. GNUstep on server. Also using Cappuccino / Objective-J for a RTF editor Open to opportuntities using Smalltalk / Objective-C. I also like C but I'm probably not a great embedded developer. :) Formerly: Backpack Designer at (Worldwide - Full Range of Motion Lifestyle) Recruiter / Project manager / Jack of All trades for C# shop. (Maritima Dominicana — SDQ,DR) Junior Software Developer (Cotinga Soft - New Orleans, USA)
Updated on October 18, 2022Comments
-
ovatsug25 over 1 year
I have been using zsh globbing for commands such as:
vim **/filename vim *.html.erb
and so on, but when I type in something like:
find . -name *mobile*
I get the response:
zsh: no matches found: *mobile*
Why?
-
Syed Ali almost 7 yearsI think it has a better answere here: unix.stackexchange.com/questions/130958/…
-
ThomasW over 4 yearsIn particular, this answer: unix.stackexchange.com/a/130967/13732
-
-
Philip almost 2 yearsI tried to reorg the above for clarity, but the edit queue has been full for hours now.