Date
May. 19th, 2024
 
2024年 4月 12日

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
I'm looking for a SOFTWARE PROJECT DIRECTOR / SOFTWARE R&D DIRECTOR position in a fresh and dynamic company. I would like to gain the right experience and extend my skills while working in great teams and big projects.
Feel free to contact me.
For more information, please view online résumé or download PDF
本人正在寻求任职 软件项目经理 / 软件技术经理 岗位的机会, 希望加⼊某个新鲜⽽充满活⼒的公司。
如有意向请随时 与我联系
更多信息请 查阅在线简历下载 PDF