110

when I try scp over zsh, I get

scp hostA:Descargas/debian-6.0.4-* [email protected]:Escritorio/Software/
zsh: no matches found: hostA:Descargas/debian-6.0.4-*

the same command work in bash

0

6 Answers 6

184

Escape your wildcard :

scp hostA:Descargas/debian-6.0.4-\*
4
  • 1
    I got the same error when trying to run a ruby resque worker with the QUEUE=* option. Thanks for the fix!
    – mogramer
    Commented Aug 29, 2014 at 2:51
  • 4
    Thanks for solution... This seems like an example of zsh being too smart for its own good...
    – Owen
    Commented Oct 13, 2016 at 14:25
  • 1
    Worked for me as well. Weird though!
    – roopunk
    Commented Jul 16, 2017 at 6:39
  • 1
    \ does the trick on macos Commented Apr 9, 2020 at 14:53
38

or add this to your .zshrc

alias scp='noglob scp'
2
  • It was so annoying to escape brackets when using ipv6, this helped.
    – Nasir
    Commented Sep 8, 2021 at 0:18
  • not it says: *: No such file or directory
    – alper
    Commented Mar 8, 2023 at 11:04
12

Too late for the party, but..

You can escape the string with quotes too

scp "hostA:Descargas/debian-6.0.4-*" "[email protected]:Escritorio/Software/"
5

Unset the NOMATCH option so that zsh leaves the text alone instead of complaining about a glob failure.

1
  • 4
    Hi, how to unset that? in .zshrc ?
    – GoingMyWay
    Commented Jun 8, 2016 at 4:34
5

This post has a nice solution to this by using the url-quote-magic plugin to automatically escape globs in scp commands. To enable it, add the following to your ~/.zshrc:

# Automatically quote globs in URL and remote references
__remote_commands=(scp rsync)
autoload -U url-quote-magic
zle -N self-insert url-quote-magic
zstyle -e :urlglobber url-other-schema '[[ $__remote_commands[(i)$words[1]] -le ${#__remote_commands} ]] && reply=("*") || reply=(http https ftp)'

When you type a glob character (like *) as part of a remote path in an scp or rsync command, zsh will automatically add a blackslash in front, like this:

scp hostA:Descargas/debian-6.0.4-\* [email protected]:Escritorio/Software/
2
  • 2
    This is a nasty but nice trick.
    – Attila O.
    Commented Nov 5, 2013 at 1:22
  • post url seems dead.
    – alper
    Commented Mar 8, 2023 at 11:05
1

I used to alias no "noglob scp" in my MacOS but with some updates I had always to type \scp at the beginning of the command so wildcards were accepted.

Changed to alias scp="\noglob scp" and it all work, with or without wildcards on command line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .