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/
相关推荐
一只栖枝1 小时前
网络安全 vs 信息安全的本质解析:数据盾牌与网络防线的辩证关系关系
网络·网络安全·信息安全·it·信息安全认证
CertiK2 小时前
CertiK《Hack3d:2025年第二季度及上半年Web3.0安全报告》(附报告全文链接)
网络
一只小鱼儿吖3 小时前
进程代理单窗口单IP技术:原理、应用与实现
网络·网络协议·tcp/ip
稳联技术3 小时前
Ethernet IP与Profinet共舞:网关驱动绿色工业的智慧脉动
网络·网络协议·tcp/ip
学习3人组4 小时前
CentOS配置网络
linux·网络·centos
~山有木兮5 小时前
LiteHub中间件之限流实现
网络·http·中间件
cui_win5 小时前
【网络】Linux 内核优化实战 - net.core.flow_limit_table_len
linux·运维·网络
BD_Marathon5 小时前
虚拟机网络检查
网络
cocologin7 小时前
RIP 技术深度解析
运维·网络·网络协议
GalaxyPokemon8 小时前
RPC-Client模块
网络·网络协议·rpc