Using wildcards in commands with zsh

Using commands such as rsync and scp with ZSH I've run into trouble. Instead of the (normal) behaviour of giving me all matching files, it won't run and returns:

➜  ~  rsync -azP user@server:~/* ~/
zsh: no matches found: user@server:~/*

How can I fix this?

My .zshrc

ZSH=$HOME/.oh-my-zsh
ZSH_THEME="robbyrussell"
plugins=(git brew)
source $ZSH/oh-my-zsh.sh
export PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/local/sbin

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!