用 rsync 复制和同步文件

rsync 走 SSH 传输、跳过未变化的文件、支持断点续传,并保留权限和时间戳。

Linux备份复制rsync 同步低风险
运行 `rsync -avh --progress 源目录/ user@host:/目标/` 即可通过 SSH 同步目录内容到远程主机。

01命令

命令
$ rsync -avh --progress source/ user@host:/dest/

02作用说明

最容易忘的一条规则:源路径末尾带斜杠表示“复制目录内容”,不带斜杠表示“复制目录本身”——一个字符决定目标目录结构。加 `-n`(dry-run)配合 `--delete` 可以先预览镜像同步会删除哪些文件再真正执行。重复执行同一条命令只会传输差异部分,所以 rsync 也常当备份工具用;传输中断后用 `--partial` 续传。

03风险

风险低风险
使用条件rsync installed on both ends (default on most distros)
!注意: --delete 会精确镜像源目录,源里消失的文件在目标端也会被删——务必先用 -n 预览。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • rsync(1) - Linux manual page
    Ubuntu Manpages · technical · 2026-09-17
    依据: rsync is a fast, versatile file copying tool; a trailing slash on the source copies the contents of the directory rather than the directory itself, and --delete deletes extraneous files from the destination.

最后验证: 2026-09-17 · 分类: 文件与文件夹