rsync
文件与目录
用法
rsync -av [source]/ [dest]/只传两棵目录树之间的差异,本地或经 ssh 都行;源路径末尾的斜杠表示它的内容,不写就会多套一层目录。
常用选项
| 选项 | 含义 |
|---|---|
| -a | Archive: recursive, keeping permissions, times and symlinks |
| -v | List what is transferred |
| -z | Compress while it travels |
| -P | Show progress and keep partial files so a transfer can resume |
| --delete | Remove files in the destination that are gone from the source |
| -n | Dry run: print what would happen and change nothing |
| --exclude | Skip paths matching a pattern |
| -e | Choose the remote shell, as in -e "ssh -p 2222" |
示例
rsync -avP big.iso server:/data/Copies with progress, and can resume later.
rsync -av --delete site/ /backup/site/Makes the backup an exact mirror.
rsync -avn src/ dst/Dry run first; nothing is written.
移动、删除和查找。有些命令不会再问一遍,所以顺手加 -i 是在救自己。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. rsync 是做什么的?
只传两棵目录树之间的差异,本地或经 ssh 都行;源路径末尾的斜杠表示它的内容,不写就会多套一层目录。
Q. 怎么写?
rsync -av [source]/ [dest]/ —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 8 个,完整列表在 man rsync。这条命令属于文件与目录。
相关命令
man 手册: man rsync