无法通过管道输入 diff 吗?

无法通过管道输入 diff 吗?

我想聪明一点,将远程文件与本地文件进行比较,而无需先手动下载它。我可以通过以下方式获取远程文件的内容

ssh user@remote-host "cat path/file.name"

然而,通过管道将其传输到diff

ssh user@remote-host "cat path/file.name" | diff path/file.name

给了我这个:

diff: missing operand after `path/file.nae'
diff: Try `diff --help' for more information.

我设置了 ssh 密钥,因此它不会提示我输入密码。有什么解决方法吗?

答案1

用于 -表示标准输入:

ssh user@remote-host "cat path/file.name" | diff path/file.name -

答案2

这是一种解决方法:diff似乎接受 <(表达式)作为论证:

diff <(ssh \"cat path/file.name/") <(cat path/file.name)

答案3

通过管道输入 diff 相当于运行

diff path/file.name

然后,一旦运行,就键入文件的全部内容。

正如您所看到的,这不是您所期望的。

答案4

diff /tmp/localtempfile <(ssh -A -o StrictHostKeyChecking=no root@server "cat /tmp/remotetempfile")

相关内容