将文件复制并附加到远程机器:cat error [英] Copy and append files to a remote machine: cat error
问题描述
所以,我有一点问题:
最初我使用 scp
将文件从本地机器复制到远程机器,然后我意识到 scp 覆盖而不是附加.但我需要它来附加.所以我做了一些谷歌搜索,这个使用 cat
和 ssh
的替代方法出现了:
Originally I was using scp
to copy a file from a local machine to a remote machine before I realized that scp overwrites instead of appends. But I need it to append. So I did some Googling and this alternative using cat
and ssh
popped up instead:
cat localfile | ssh user@remoteserver "cat >> remotefile"
问题是,每当我使用该方法时,我都会遇到这个有趣的错误:
Problem is, I get this interesting error whenever I use that method:
bash: cat: command not found
当我通常 ssh 到我的远程机器时,我可以 cat
就好了,所以我正在寻找帮助解决这个问题或找到一种方法来仅使用来自本地主机的命令进行附加.
When I normally ssh into my remote machine, I can cat
just fine, so I'm looking for either help fixing this problem or finding a way to append using only commands from my local host.
推荐答案
通过 ssh 运行时,您的 $PATH
可能会有所不同.
Your $PATH
may be different when running through ssh.
无论如何,您可以运行 which cat
来查找 cat
实际放置在远程机器上的位置,并在命令调用中硬编码路径.例如
Anyway, you can run which cat
to find where cat
is actually placed on the remote machine and hard code the path in the command invocation. For instance
ssh user@remoteserver "/sbin/cat >>remotefile" <localfile
(顺便说一句,你真的不需要本地的cat
).
(BTW, you don't really need the local cat
).
另一种选择是使用支持附加的 SFTP 客户端.
Another option would be to use a SFTP client with support for appending.
这篇关于将文件复制并附加到远程机器:cat error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!