如何逃脱和进入SCP

问题描述 投票:4回答:3

是,我确实意识到已经问过一千遍如何在scp中转义spaces,但是我不能使用符号来实现,所以如果该符号是目录名称。

[sorunome@sorunome-desktop tmp]$ scp test.txt "bpi:/home/sorunome/test & stuff"
zsh:1: command not found: stuff
lost connection

&符号似乎使事情变得很混乱,使用\&不能解决问题,因为找不到远程目录:

[sorunome@sorunome-desktop tmp]$ scp test.txt "bpi:/home/sorunome/test \& stuff"
scp: ambiguous target

甚至都没有省略引号并在工作的所有位置都添加\:

[sorunome@sorunome-desktop tmp]$ scp test.txt bpi:/home/sorunome/test\ \&\ stuff
zsh:1: command not found: stuff
lost connection

所以,有什么想法吗?

shell escaping scp
3个回答
7
投票

同时避开空格和&符对我有用:

scp source_file "user@host:/dir\ with\ spaces\ \&\ ampersand"

出于某些原因仍需要使用引号。


0
投票

使用scp或cp时,特殊字符可能会破坏文件路径。您可以通过转义特殊字符来解决此问题。

使用cp,您可以使用转义特殊字符的常规方法,该方法前面带有反斜杠。例如,可以使用以下命令复制带有空格的路径:

cp photo.jpg My\ Pictures/photo.jpg

scp中的远程路径无法使用此方法进行转义。您需要使用双反斜杠转义特殊字符。使用相同的示例,“我的照片”文件夹将使用以下命令转义其空间:

scp photo.jpg "user@remotehost:/home/user/My\\ Photos/photo.jpg"

双引号也很重要,带有特殊字符的整个路径必须用双引号引起来。

来源:https://dominichosler.wordpress.com/2011/08/27/using-scp-with-special-characters/


0
投票

我找到了!!如果您需要转义%,请使用%%

© www.soinside.com 2019 - 2024. All rights reserved.