rsyncからすべてのドット下線ファイルを除外します。

rsyncからすべてのドット下線ファイルを除外します。

rsync -avドットアンダースコア()で._example.txt始まるすべてのファイルを使用しますが、除いて.DS_Storeファイルを無視する方法は?

答え1

あなたは試すことができます--exclude="<filePattern>"

rsync -av --exclude="._*" --exclude=".DS_Store" <source> <destination>

答え2

を使用すると、名前が下線で始まるすべてのファイルとディレクトリは無視され--exclude='._*'ます。rsyncを使用すると、--exclude='.DS_Store'他の種類のファイルは無視されます。

答え3

複数のオプションでコマンドラインを複雑にせずに複数の除外ルールを持つ場合は、このオプションを除外するパターンを一覧表示するファイルと一緒に--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がターゲットから除外されたファイルも削除されます。

答え4

._*一致するファイルとディレクトリを除外するには、以前の.DS_Store答えの1つで十分です。

rsync -av --exclude='._*' --exclude='.DS_Store' src dst

一方、質問に正確に答えるために、このコードスニペットは、次のものと_*一致するディレクトリを含めながら、基準に一致するファイルを除外します.DS_Store

rsync -av --include '.DS_Store/' --include '._*/' --exclude '.DS_Store' --exclude '._*' src dst

実際のケース

# Set up the example directory tree
mkdir -p src/a/.DS_Store src/a/._example.dir dst
touch src/.DS_Store src/._example.txt src/a/.DS_Store/keep src/a/._example.dir/keep src/item src/a/another

# Show what we have
find src -type f

    src/.DS_Store
    src/._example.txt
    src/a/.DS_Store/keep
    src/a/._example.dir/keep
    src/a/another
    src/item

# Copy it. Omit matching files but keep the directories
rsync -av --include '.DS_Store/' --include '._*/' --exclude '.DS_Store' --exclude '._*' src/ dst

    sending incremental file list
    ./
    item
    a/
    a/another
    a/.DS_Store/
    a/.DS_Store/keep
    a/._example.dir/
    a/._example.dir/keep

# Tidy up
rm -rf src dst

関連情報