[Google-oriented Programming(GoP)] FAQs about SCP to transfer files

FAQs about SCP

zsh report errors no matches found while zsh uses scp to transfer files with wildcards

1
2
$ scp [email protected]:/Users/cloudolife/.ssh/* ~/.ssh/
sh: no matches found: [email protected]:/Users/cloudolife/.ssh/*

The reason is because zsh tries to expand *. No matches error will be reported when the file cannot be found locally.

There are two approaches:

Option 1, Avoid zsh to expand *

  • Add a backslash() before * to prevent escaping

    1
    $ scp [email protected]:/Users/cloudolife/.ssh\* ~/.ssh/
  • Or, Enclose the path (or the path including the server) with single or double quotes

    1
    2
    3
    4
    # Single quotation mark, including server address
    scp '[email protected]:/Users/cloudolife/.ssh/*' ~/.ssh/
    # Double quotation mark, without server address
    scp [email protected]:"/Users/cloudolife/.ssh/*" ~/.ssh/

But sometimes the above two methods using wildcards for local paths are invalid, then refer to next:

Option 2, Switch to /bin/bash

/bin/bash does not have the problem of expanding *.

1
$ chsh -s /bin/bash

zsh 使用scp传输文件时使用通配符报错_SimonLiu的博客-CSDN博客