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/
相关推荐
一只小姜丝3321 小时前
解决各大浏览器中http地址无权限调用麦克风摄像头问题
网络·vue.js·网络协议·http
Hacker_xingchen8 小时前
网络安全扫描--基础篇
网络·安全·web安全
hgdlip9 小时前
如果更换ip地址会怎么样?网络ip地址怎么更换
网络·网络协议·tcp/ip
心随_风动9 小时前
网络七层模型—OSI参考模型详解
网络
桃酥40310 小时前
1.介绍一下TCP/IP模型和OSI模型的区别【中高频】
网络
Mr_wilson_liu10 小时前
ssh被暴力访问了,怎么拦截ip
网络·tcp/ip·ssh
北京耐用通信12 小时前
半导体晶圆精控:ethercat转profient网关数据提升制造精度
网络·制造·ethercat·ethercat总线
Ljw...13 小时前
HTTP
linux·网络·网络协议·http
小杨小杨113 小时前
RIP-AV:使用上下文感知网络进行视网膜动脉/静脉分割的联合代表性实例预训练
网络
追风赶月、13 小时前
【网络】HTTPS协议原理
网络·网络协议·https