Regular-Expression

從 rsync 中排除所有點下劃線文件

  • July 27, 2020

如何使用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 也刪除目標上的這些排除文件。

引用自:https://unix.stackexchange.com/questions/456501