Regular-Expression
從 rsync 中排除所有點下劃線文件
如何使用
rsync -av
但排除以點下劃線 ( ) 開頭的所有文件._example.txt
並忽略.DS_Store
文件?
你可以試試
--exclude="<filePattern>"
rsync -av --exclude="._*" --exclude=".DS_Store" <source> <destination>
要擁有多個排除規則而不會使命令行與多個
--exclude
選項混淆,您可以改為使用-F
選項和.rsync-filter
列出要排除的模式的文件。-F The -F option is a shorthand for adding two --filter rules to your command. The first time it is used is a shorthand for this rule: --filter='dir-merge /.rsync-filter' This tells rsync to look for per-directory .rsync-filter files that have been sprinkled through the hierarchy and use their rules to filter the files in the transfer.
.rsync-filter
以下是要備份的文件夾根目錄中的文件範例:- /temp - /lost+found # Windows thumbnails -p Thumbs.db # MS Office temporary files -p ~$* # common Mac junk -p .TemporaryItems -p .DS_Store -p ._*
後面的
p
修飾符-
表示“易腐爛的”,這將使 rsync 也刪除目標上的這些排除文件。