linux与linux互传命令
linux与linux互传命令详细介绍
在 Linux 系统之间进行文件传输可以使用多种命令,下面为你介绍一些常用的命令及其使用方法:
1. scp 命令
scp(Secure Copy)是一个基于 SSH 协议的安全文件复制命令,它可以在本地和远程系统之间或者两个远程系统之间复制文件和目录。
- 从本地复制文件到远程系统
bash
/path/to/local/file username@remote_host:/path/to/remote/destination
- 从远程系统复制文件到本地
bash
username@remote_host:/path/to/remote/file /path/to/local/destination
- 复制目录
若要复制整个目录,需加上-r选项:
bash
/path/to/local/directory username@remote_host:/path/to/remote/destination
2. rsync 命令
rsync 是一个强大的文件同步工具,它可以高效地复制和同步文件,并且支持增量传输,也就是只传输文件中发生变化的部分。
- 从本地同步目录到远程系统
bash
/path/to/local/directory username@remote_host:/path/to/remote/destination
选项说明:
-a:归档模式,递归复制目录,保留文件的权限、时间戳等属性。-v:详细模式,显示同步过程。-z:压缩传输,减少传输的数据量。- 从远程系统同步目录到本地
bash
username@remote_host:/path/to/remote/directory /path/to/local/destination
3. sftp 命令
sftp(Secure File Transfer Protocol)是一个交互式的安全文件传输协议,基于 SSH 协议。
- 连接到远程系统
bash
username@remote_host
- 上传文件
在sftp提示符下,使用put命令上传文件:
bash
put /path/to/local/file
- 下载文件
使用get命令下载文件:
bash
get /path/to/remote/file
- 退出
sftp
bash
912
以上这些命令都依赖于 SSH 服务,因此确保远程系统的 SSH 服务已开启,并且你有相应的权限。