scp
是一个用于在 Linux 系统之间进行文件传输的命令行工具,它使用 SSH 协议进行安全的文件传输。下面是 scp
命令的详细解释和常见用法:
基本语法
scp [选项] 源文件 目标位置
常用选项:
-r:递归复制整个目录及其内容。
-P <port>:指定远程服务器的 SSH 端口号。
-p:保留文件的原始修改时间和权限。
-q:安静模式,不显示传输过程信息。
-v:显示详细的传输过程信息。
-C:开启压缩传输。
例:
1、从本地复制文件到远程服务器(例如:用户root,本地ip为:192.168.0.6,目标ip为:192.168.0.7)
scp /path/to/local/file root@192.168.0.7:/path/to/destination
2、从远程服务器复制文件到本地:
scp root@192.168.0.7:/path/to/remote/file /path/to/destination
3、递归复制目录及其内容到远程服务器:
scp -r /path/to/local/directory root@192.168.0.7:/path/to/destination
4、从远程服务器复制目录及其内容到本地:
scp -r root@192.168.0.7:/path/to/remote/directory /path/to/destination
5、指定端口号进行传输:
scp -P 2222 /path/to/local/file root@192.168.0.7:/path/to/destination
6、保留文件的原始修改时间和权限:
scp -p /path/to/local/file root@192.168.0.7:/path/to/destination
7、在传输过程中启用压缩:
scp -C /path/to/local/file root@192.168.0.7:/path/to/destination
8、安静模式,不显示传输过程信息:
scp -q /path/to/local/file root@192.168.0.7:/path/to/destination