Using wildcards in commands with zsh

This is related with how ZSH manage globbing characters to generate filenames. By default, ZSH will generate the filenames and throw an error before executing the command if it founds no matches.

There are many ways to bypass this behavior, here are some of them:

  • The quickest is to enclose the globbing characters with quotes.
$ rsync -azP "user@server:~/*" ~/
  • For a permanent change, you'll have to add the following in your .zshrc file:
unsetopt nomatch

This will prevent ZSH to print an error when no match can be found.

  • Another possibility is to disable globbing for a particular command by using the noglob command modifier. By setting an alias in .zshrc for example:
alias scp='noglob scp'

I have been using zpretzo for quite a few months and also experienced this issue. I came across a neat and useful solution if you don't want to make any changes: simply prepend backslash to the command.

~/p/b/a/files ❯❯❯ scp *.* myserver@host:~/
*.*: No such file or directory

~/p/b/a/files ❯❯❯ \scp *.* myserver@host:~/
jquery.min.js                              100%   93KB  92.6KB/s   00:00
json2.min.js                               100%   3377   3.3KB/s   00:00

I hope this helps!


This solves your problem without having to manually quote the URLs

autoload -U url-quote-magic  
zle -N self-insert url-quote-magic

# sort it out for SCP
some_remote_commands=(scp rsync)
zstyle -e :urlglobber url-other-schema \
  '[[ $some_remote_commands[(i)$words[1]] -le ${#some_remote_commands} ]] && reply=("*") || reply=(http https ftp)'