macos 如何使用 SSH 和 MAC OS X 终端跨计算机复制文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3710946/
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 to copy files across computers using SSH and MAC OS X Terminal
提问by alvincrespo
I'm trying to copy my .profile, .rvm and .ssh folders/files to a new computer and keep getting a "not a regular file" response. I know how to use the cp
and ssh
commands but I'm not sure how to use them in order to transfer files from one computer to another.
我正在尝试将我的 .profile、.rvm 和 .ssh 文件夹/文件复制到一台新计算机,并不断收到“非常规文件”响应。我知道如何使用cp
和ssh
命令,但我不确定如何使用它们将文件从一台计算机传输到另一台计算机。
Any help would be great, thanks!
任何帮助都会很棒,谢谢!
回答by Ether
You can do this with the scp
command, which uses the ssh protocol to copy files across machines. It extends the syntax of cp
to allow references to other systems:
您可以使用该scp
命令执行此操作,该命令使用 ssh 协议跨机器复制文件。它扩展了 的语法cp
以允许引用其他系统:
scp username1@hostname1:/path/to/file username2@hostname2:/path/to/other/file
Copy something from this machine to some other machine:
从这台机器复制一些东西到其他机器:
scp /path/to/local/file username@hostname:/path/to/remote/file
Copy something from another machine to this machine:
从另一台机器复制一些东西到这台机器:
scp username@hostname:/path/to/remote/file /path/to/local/file
Copy with a port number specified:
使用指定的端口号复制:
scp -P 1234 username@hostname:/path/to/remote/file /path/to/local/file
回答by Sam
First zip or gzip the folders:
Use the following command:
首先压缩或 gzip 文件夹:
使用以下命令:
zip -r NameYouWantForZipFile.zip foldertozip/
zip -r NameYouWantForZipFile.zip foldertozip/
or
或者
tar -pvczf BackUpDirectory.tar.gz /path/to/directory
tar -pvczf 备份目录.tar.gz /path/to/directory
for gzip compression use SCP:
对于 gzip 压缩使用 SCP:
scp [email protected]:~/serverpath/public_html ~/Desktop
scp [email protected]:~/serverpath/public_html ~/Desktop
回答by Andy Lester
You may also want to look at rsync if you're doing a lot of files.
如果您正在处理大量文件,您可能还想查看 rsync。
If you're going to making a lot of changes and want to keep your directories and files in sync, you may want to use a version control system like Subversion or Git. See http://xoa.petdance.com/How_to:_Keep_your_home_directory_in_Subversion
如果您要进行大量更改并希望保持目录和文件同步,则可能需要使用诸如 Subversion 或 Git 之类的版本控制系统。见http://xoa.petdance.com/How_to:_Keep_your_home_directory_in_Subversion