同步 / 下 /usr /boot,排除 /proc /tmp:
rsync -av --exclude "proc" --exclude "tmp" /source/ /dest/
關鍵規則:路徑必須為相對路徑,相對於來源根目錄。
錯誤示範: --exclude "/checkout"(絕對路徑不生效)。
# 源端 /home/yjwan/bashshell 下有 checkout 目錄
rsync -av --exclude "checkout" yjwan@172.16.251.241:/home/yjwan/bashshell /tmp
# 目標端 /tmp/bashshell 不會有 checkout
--exclude "checkout/123"
--exclude "fire*" # 所有 fire 開頭的檔案/目錄
排除項目過多時,寫入檔案 /exclude.list(絕對路徑),內容每行一個相對路徑:
checkout
fire*
downloads/test/*
執行:
rsync -av --exclude-from="/exclude.list" yjwan@172.16.251.241:/home/yjwan/bashshell /tmp
rsync -av /source/ | grep "^-" | wc -l(或 ls -AlR | grep "^-" | wc -l)rsync -av --exclude "fire*" /source/ | grep "^-" | wc -l-z, --compress:傳輸壓縮(內網小檔案可不必)--password-file:僅適用於 rsync daemon 模式,非 SSH 密碼--stats:顯示傳輸統計--progress:顯示每檔進度,大檔案傳輸極實用-P:等同 --partial --progress,支援斷點續傳與進度顯示