Date
Sep. 8th, 2024
 
2024年 8月 6日

Post: RSYNC Cheatsheet

RSYNC Cheatsheet

Published 15:02 Feb 10, 2018.

Created by @ezra. Categorized in #macOS, and tagged as #Cheatsheet, #UNIX/Linux, #macOS.

Source format: Asciidoc

Table of Content
Commands Description
rsync /path/to/file.ext /path/to/dest

简单的复制文件 file.ext/path/to/dest 目录中

rsync -n /path/to/file.ext /path/to/dest

演习模式:简单的复制文件 file.ext/path/to/dest 目录中

  • -n: 演习、排练,并不会进行真实的操作

rsync --size-only /path/to/file.ext /path/to/dest

简单的复制文件 file.ext/path/to/dest 目录中,仅比较文件大小

  • --size-only: 仅比较文件大小

rsync -r /path/to/folder /path/to/dest

递归复制文件夹 /path/to/folder/path/to/dest 目录中

  • -r: 递归

  • /source/folder: 复制文件夹本身及其内容

rsync -r /path/to/folder/ /path/to/dest

递归复制文件夹 /path/to/folder/ 中的内容到 /path/to/dest 目录中

  • -r: 递归

  • /source/folder/: 只复制文件夹内容而不复制其本身

rsync -a /path/to/folder/ /path/to/dest

复制 /path/to/folder/ 中的内容到 /path/to/dest 目录中,并保持源属性

  • -a: archive (-rlptgoD), 将保持源属性

rsync -av /path/to/folder/ /path/to/dest
  • -v: verbose, 打印进度等详细信息

rsync -ah --progress /path/to/folder/ /path/to/dest
  • -h: human readable, 以人类可读的形式打印

  • --progress: 过程中打印进度信息

rsync -ah --progress --partial /path/to/folder/ /path/to/dest
  • --partial: 意外中断后保留已经复制的文件部分以便在恢复后继续进行复制(通常在复制大文件时使用)

rsync -ahP /path/to/folder/ /path/to/dest
  • -P: 等于 --progress --partial

rsync -ahP --delete /path/to/folder/ /path/to/dest

复制 /path/to/folder/ 中的内容到 /path/to/dest 目录中,并保持源属性,如果后者中存在前者中不包含的文件则会被删除

  • --delete: 如果目标目录中存在源目录中不存在的内容则会被删除

rsync -ahP --remove-source-files /path/to/folder/ /path/to/dest

复制 /path/to/folder/ 中的内容到 /path/to/dest 目录中,并保持源属性,复制完成后会移除前者

  • --remove-source-files: 移除源文件(但会保留子目录结构)

    • 之后你可以执行 find /path/to/folder/ -type d -empty -delete 来移除这些子目录结构

Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
程序猿、设计师、奇怪的博主。
苹果死忠、热爱色彩斑斓的世界。
如有意向请随时 与我联系