红穆笔记

rsync

一種快速,通用,遠程(和本地)文件複製工具,默認使用 SSH。 如果要指定遠程路徑,請使用 `user@host:path/to/file_or_directory`

100% 瀏覽器本地處理 0 數據上傳

常用示例

複製文件

rsync {{路徑/到/來源}} {{路徑/到/目標}}

使用歸檔模式遞歸拷貝文件,並保留所有屬性,不解析軟鏈接

rsync {{[-a|--archive]}} {{路徑/到/來源}} {{路徑/到/目標}}

將文件以歸檔模式並保留幾乎所有屬性進行傳輸,並以人類可讀方式輸出詳細信息和進度條,中斷時保留部分信息

rsync {{[-zvhP|--compress --verbose --human-readable --partial --progress]}} {{路徑/到/來源}} {{路徑/到/目標}}

以遞歸模式傳輸文件

rsync {{[-r|--recursive]}} {{路徑/到/來源}} {{路徑/到/目標}}

將目錄下的所有內容(不包含該目錄),以遞歸方式傳輸

rsync {{[-r|--recursive]}} {{路徑/到/來源/}} {{路徑/到/目標}}

歸檔方式傳輸目錄,保留幾乎所有屬性,解析軟連接,並忽略已傳輸的文件

rsync {{[-auL|--archive --update --copy-links]}} {{路徑/到/來源}} {{路徑/到/目標}}

傳輸目錄到運行 `rsyncd` 的遠端,並刪除目標目錄中源目錄中不存在的文件

rsync {{[-r|--recursive]}} --delete rsync://{{host}}:{{路徑/到/來源}} {{路徑/到/目標}}

指定本地和遠程之間通信方式,使用指定端口,並顯示進度條

rsync {{[-e|--rsh]}} 'ssh -p {{端口}}' --info=progress2 {{host}}:{{路徑/到/來源}} {{路徑/到/目標}}

提示:花括號{{…}}是需要替換的參數(路徑、文件名等);命令只在本機終端執行,本站不保存任何輸入。

英文原文對照

展開英文說明與示例(來源 tldr-pages)

Transfer files either to or from a remote host (but not between two remote hosts), by default using SSH. To specify a remote path, use `user@host:path/to/file_or_directory`. More information

Transfer a file (use `--dry-run` to simulate the transfer)

rsync {{path/to/source}} {{path/to/destination}}

Use archive mode (recursively copy directories, copy symlinks without resolving, and preserve permissions, ownership, and modification times)

rsync {{[-a|--archive]}} {{path/to/source}} {{path/to/destination}}

Compress the data as it is sent to the destination, display verbose and human-readable progress, and keep partially transferred files if interrupted

rsync {{[-zvhP|--compress --verbose --human-readable --partial --progress]}} {{path/to/source}} {{path/to/destination}}

Recursively copy directories and ensure each file is fully committed to disk rather than remaining in RAM

rsync {{[-r|--recursive]}} --fsync {{path/to/source}} {{path/to/destination}}

Transfer directory contents, but not the directory itself

rsync {{[-r|--recursive]}} {{path/to/source}}/ {{path/to/destination}}

Use archive mode, resolve symlinks, and skip files that are newer on the destination

rsync {{[-auL|--archive --update --copy-links]}} {{path/to/source}} {{path/to/destination}}

Transfer a directory from a remote host running `rsyncd` and delete files on the destination that do not exist on the source

rsync {{[-r|--recursive]}} --delete rsync://{{host}}:{{path/to/source}} {{path/to/destination}}

Transfer a file over SSH using a different port than the default (22) and show global progress

rsync {{[-e|--rsh]}} 'ssh -p {{port}}' --info=progress2 {{host}}:{{path/to/source}} {{path/to/destination}}

命令信息

命令名rsync
用途一種快速,通用,遠程(和本地)文件複製工具,默認使用 SSH。 如果要指定遠程路徑,請使用 `user@host:path/to/file_or_directory`
適用平臺通用
示例數量8 條
官方文檔https://download.samba.org/pub/rsync/rsync.1
數據來源tldr-pages(CC-BY-4.0)· 社區中文翻譯

常見問題

rsync 命令是做什麼的?

一種快速,通用,遠程(和本地)文件複製工具,默認使用 SSH。 如果要指定遠程路徑,請使用 `user@host:path/to/file_or_directory`

rsync 怎麼用?

頁面按場景列出了8 條常用示例:每條示例先說明用途,再給出可直接複製的完整命令(花括號裏是需要替換的參數)。

rsync 最常用的操作是什麼?

複製文件:rsync {{路徑/到/來源}} {{路徑/到/目標}}

命令裏的花括號是什麼意思?

花括號{{…}}表示需要替換成你自己的值,例如路徑、文件名;同名參數方括號(如 [-C|--directory])表示可選寫法。