如何使用 bash 将文件从一台基于 Unix 的服务器移动到另一台服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10917270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I move a file from one unix based server to another using bash?
提问by Eman
I have two servers. I would like to move a file from a directory in server A to a directory in server B using bash. Anyone have any ideas on what the best way to do this would be?
我有两台服务器。我想使用 bash 将文件从服务器 A 中的目录移动到服务器 B 中的目录。任何人都知道最好的方法是什么?
Thanks in advance.
提前致谢。
回答by DonCallisto
Why don't you use scp(take a look) or rsync(again, you can find some information here) ?
你为什么不使用scp(看一看)或rsync(同样,你可以在这里找到一些信息)?
回答by Luis Ramirez-Monterosa
copy it
复制它
$ scp user@server:/location/of/file .
delete it
删除它
$ ssh user@server 'rm /location/of/file'
回答by paulsm4
Standard commands to "move a file" include "cp" (if the remote directory is mounted), "scp" (the secure successor to "rcp") and, of course, "ftp". Any of these commands can be scripted with "bash". To "move" a file, your script would "rm" the original file.
“移动文件”的标准命令包括“cp”(如果安装了远程目录)、“scp”(“rcp”的安全后继),当然还有“ftp”。这些命令中的任何一个都可以用“bash”编写脚本。要“移动”文件,您的脚本将“rm”原始文件。
If you're doing this regularly, for many files, some of which might already exist (and not need to be re-copied), then perhaps "rsync" might be a better approach:
如果您经常这样做,对于许多文件,其中一些文件可能已经存在(不需要重新复制),那么“rsync”可能是更好的方法:
http://www.howtoforge.com/mirroring_with_rsync
http://www.howtoforge.com/mirroring_with_rsync
'Hope that helps!
'希望有帮助!

