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 小时前
【Linux】操作系统入门:冯诺依曼体系结构
linux·开发语言·网络·c++
思科小白白1 小时前
【无标题】
网络·智能路由器
yayaer22 小时前
GOOSE 协议中MAC配置
服务器·网络·goose
嵌入式在学无敌大神2 小时前
IP协议、以太网包头及UNIX域套接字
网络·tcp/ip·unix
小突突突4 小时前
个人博客系统测试报告
运维·网络·功能测试
triticale4 小时前
【Java】网络编程(Socket)
java·网络·socket
wanhengidc4 小时前
服务器中存储空间不足该怎么办?
运维·服务器·网络
soulermax5 小时前
数字ic后端设计从入门到精通4(含fusion compiler, tcl教学)CMOS VLSI Design
网络·硬件架构
bing_1586 小时前
什么是IoT长连接服务?
网络·物联网·长连接服务
christine-rr6 小时前
【25软考网工】第六章(4)VPN虚拟专用网 L2TP、PPTP、PPP认证方式;IPSec、GRE
运维·网络·网络协议·网络工程师·ip·软考·考试