[英]Append content from one file to another in Linux
I have two files, file1
on server 1 and file2
on server 2. 我有两个文件,服务器1上的
file1
和服务器2上的file2
。
Now I want to write a script to append the contents of file2
(from server 2) to file1
(on server 1), that is, without overwriting the original contents. 现在我想编写一个脚本追加的内容
file2
(从服务器2) file1
(在服务器1),也就是说,没有覆盖原来的内容。
How can I do this with a shell script (using Ubuntu Linux)? 如何使用Shell脚本(使用Ubuntu Linux)执行此操作?
ssh server2 "cat /path/to/file2" | ssh server1 "cat >> /path/to/file1"
If minimizing network traffic is an issue, use the trickier-to-quote version: 如果最小化网络流量是一个问题,请使用更复杂的报价版本:
ssh server2 'cat /path/to/file2 | ssh server1 "cat >> /path/to/file2"'
The first version transfers the file to your local host, then to server1
. 第一个版本将文件传输到本地主机,然后传输到
server1
。 The second version transfers the file directly from server2
to server1
. 第二个版本将文件直接从
server2
传输到server1
。 (If either file path contains spaces, the quoting becomes much trickier.) (如果任何一个文件路径都包含空格,则引用会变得更加棘手。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.