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/
相关推荐
梁诚斌2 分钟前
VSOMEIP代码阅读整理(1) - 网卡状态监听
运维·服务器·网络
ZachOn1y1 小时前
计算机网络:计算机网络概述 —— 描述计算机网络的参数
网络·tcp/ip·计算机网络·考研必备
我命由我123451 小时前
SSL 协议(HTTPS 协议的关键)
网络·经验分享·笔记·学习·https·ssl·学习方法
两点王爷2 小时前
使用WebClient 快速发起请求(不使用WebClientUtils工具类)
java·网络
wusam2 小时前
螺蛳壳里做道场:老破机搭建的私人数据中心---Centos下Docker学习03(网络及IP规划)
运维·服务器·网络·docker·容器
什么鬼昵称4 小时前
Pikachu-xxe-xxe漏洞
网络·安全·xxe
真正的醒悟7 小时前
资源网站分享
网络
神一样的老师7 小时前
面向MQTT基础物联网网络的Age-of-Information感知的保留消息策略
网络·物联网
中草药z7 小时前
【JavaEE】http/https 超级详解
网络·笔记·网络协议·学习·http·https·计网