rsync常用命令

从远程服务器复制文件到本地

语法

bash 复制代码
rsync [options] user@remote_host:/path/to/remote/source /path/to/local/destination

示例

bash 复制代码
rsync -avz -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/

从本地复制文件到远程服务器

语法

bash 复制代码
rsync [options] /path/to/local/source user@remote_host:/path/to/remote/destination

示例

bash 复制代码
rsync -avz -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/

选项说明

  • -a:归档模式,表示递归传输并保持文件属性。
  • -v:详细输出,显示传输过程中的信息。
  • -z:压缩文件数据在传输过程中减少带宽使用。
  • -e ssh:指定使用 SSH 作为远程 shell。

处理权限问题

有时会遇到权限问题,可以使用 sudo 提升权限:

从远程服务器复制文件到本地:
bash 复制代码
sudo rsync -avz -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/
从本地复制文件到远程服务器:
bash 复制代码
sudo rsync -avz -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/

排除文件或目录

如果要排除某些文件或目录,可以使用 --exclude 选项:

从远程服务器复制文件到本地,排除特定目录:
bash 复制代码
rsync -avz --exclude 'excluded_dir' -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/
从本地复制文件到远程服务器,排除特定文件:
bash 复制代码
rsync -avz --exclude 'excluded_file' -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/

显示传输进度

为了更好地了解传输进度,可以添加 --progress 选项:

从远程服务器复制文件到本地,显示进度:
bash 复制代码
rsync -avz --progress -e ssh user@remote_host:/path/to/remote/source/ /path/to/local/destination/
从本地复制文件到远程服务器,显示进度:
bash 复制代码
rsync -avz --progress -e ssh /path/to/local/source/ user@remote_host:/path/to/remote/destination/
相关推荐
是Dream呀27 分钟前
Python从0到100(八十六):神经网络-ShuffleNet通道混合轻量级网络的深入介绍
网络·python·神经网络
山楂树の2 小时前
计算机网络 性能指标相关
网络·计算机网络
泪不是Web妳而流2 小时前
【HTML入门】Sublime Text 4与 Phpstorm
网络·经验分享·编辑器·html·学习方法·sublime text·phpstorm
star010-2 小时前
一文学会HTML编程之视频+图文详解详析
前端·网络·网络安全·html·html5
学问小小谢8 小时前
第26节课:内容安全策略(CSP)—构建安全网页的防御盾
运维·服务器·前端·网络·学习·安全
一ge科研小菜鸡8 小时前
网络安全实战指南:攻防技术与防御策略
网络
马立杰12 小时前
H3CNE-33-BGP
运维·网络·h3cne
Mason Lin12 小时前
2025年1月22日(网络编程 udp)
网络·python·udp
字节全栈_rJF12 小时前
概述、 BGP AS 、BGP 邻居、 BGP 更新源 、BGP TTL 、BGP路由表、 BGP 同步
网络·智能路由器·php
EchoToMe12 小时前
电信传输基本理论/5G网络层次架构——超三万字详解:适用期末考试/考研/工作
网络·5g·架构