我如何使用scp与文件名冒号文件? [英] How can I scp a file with a colon in the file name?

查看:1519
本文介绍了我如何使用scp与文件名冒号文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 SCP 庆典复制文件用冒号()字符在源文件名。我命令我使用的模糊版本是:

I'm trying to copy a file using scp in bash with a colon (:) character in the source filename. The obfuscated version of my command I'm using is:

scp file\:\ name.mp4 user@host:"/path/to/dest"

我得到这个错误:

I get this error:

ssh: Could not resolve hostname Portal 2: Name or service not known

我知道我可以只重命名该文件并删除,但我想知道是否有可能逃脱结肠

I know I could just rename the file and remove the :, but I'd like to know if it's possible to escape the colon.

推荐答案

不太一个庆典逃避的问题,这是 SCP 治疗 X:作为主机preFIX,请尝试:

Not quite a bash escaping problem, it's scp treating x: as a host prefix, try:

scp ./file:\ name.mp4 user@host:"/path/to/dest"

使用相对(例如 ./ )或完全合格的路径prevents此行为。的OpenSSH的 SCP 特殊案件的文件名开头的用冒号允许它没有问题工作。

Using relative (e.g. ./) or fully qualified paths prevents this behaviour. OpenSSH's scp special-cases a filename that starts with a colon allowing it to work without problems.

要回答的如何的逃脱问题:,你并不需要,但 \\: 的作品。地方,一个时:

To answer the question about how to escape :, you don't need to, but "\:" works. Places that a : is used:


  1. 空命令,没必要逃避,虽然你可以,就像 \\ E \\ C \\ ^ h \\ o富它的命令没有影响(没有效果并不完全正确,如果你逃避一个或多个字符,将prevent别名相匹配)

  2. PATH (和其他人, CDPATH MAILPATH )转义值还没有有用的效果(我一直无法从包含的目录在我的PATH运行程序的,这是一个有点意外)

  3. 参数扩展 $ {名称:-x} 多,名称必须 [A-ZA-Z _] [A-ZA-Z0-9 _] ,所以没有必要逃避变量名称,因为没有歧义,没必要逃避随后的参数扩展的其他变化

  4. 三元只在变量和数字操作,无需逃生

  5. == =〜与模式类,如 [:数字:] ,您可以用逃脱\\:,但我在一个头绪,可能永远是有用的...

  6. 命令或函数名之内,没有必要逃避, \\ 没有有用的效果

  1. the null command :, no need to escape, though you can, just like \e\c\h\o foo it has no effect on the command ("no effect" is not completely true, if you escape one or more characters it will prevent an alias being matched)
  2. PATH (and others, CDPATH, MAILPATH) escaping the values has no useful effect (I have been unable to run a program in my PATH from a directory containing a :, which is a little unexpected)
  3. parameter expansion ${name:-x} and more, name must be [a-zA-Z_][a-zA-Z0-9_], so no need to escape variables names, and since there's no ambiguity, no need to escape subsequent : in the other variations of parameter expansion
  4. ? : trinary operates only on variables and numbers, no need to escape
  5. == and =~ with classes in the pattern like [[:digit:]], you can escape with \: but I'm at a loss as to how that might ever be useful...
  6. within command or function names, no need to escape, \: has no useful effect

(注意null命令就是,你可以有一个命令或功能命名,如:富,它可以在不逃避调用,在这方面是不同的,其中指定命令 #foo 会需要转义。)

(Note that the null command is just :, you can have a command or function named like ":foo" and it can be invoked without escaping, in this respect it's different to # where a command named #foo would need to be escaped.)

这篇关于我如何使用scp与文件名冒号文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆