rsync - 最上位ファイルを含み、ディレクトリを除外します。

rsync - 最上位ファイルを含み、ディレクトリを除外します。

file1.txtすべてのトップレベルファイル(、、file2)を含めたいです/top/dir1/。どうすればいいですか?

次の方法を試しましたが、うまくいきません。

$ tree
.
└── from
    ├── file1.txt
    ├── file2
    └── top
        ├── dir1
        │   └── file3.txt
        └── dir2
            └── file4.txt

1回の試みでトップレベルのファイルがありませんでした。

$ rsync --dry-run \
>       --include='top/' \
>       --include='top/dir1/' \
>       --include='top/dir1/***' \
>       --exclude='top/*' \
>       --exclude="*" \
>       -av from/* .
building file list ... done
top/
top/dir1/
top/dir1/file3.txt

他の試みにはトップレベルのファイルが含まれますが、dir2 は除外されません。

$ rsync --dry-run \
>       --include="*" \
>       --include='top/' \
>       --include='top/dir1/' \
>       --include='top/dir1/***' \
>       --exclude='top/*' \
>       --exclude="*" \
>       -av from/* .
building file list ... done
file1.txt
file2
top/
top/dir1/
top/dir1/file3.txt
top/dir2/
top/dir2/file4.txt

ベストアンサー1

rsyncのソースパスでは使用しないでください*。 rsyncは、これらの項目を完全に完全に見つけることができます。

これにより、効果的にrsyncを呼び出すことができます。

rsync --dry-run \
   --include="*" \
   --include='top/' \
   --include='top/dir1/' \
   --include='top/dir1/***' \
   --exclude='top/*' \
   --exclude="*" \
   -av from/file1.txt from/file2 from/top .

包含パターンと除外パターンはソースルートに基づいているため、--include 'top/'同じパターンは一致しません。

これを行う:

rsync --dry-run \
   --include="/*" \
   --include='/top/' \
   --include='/top/dir1/' \
   --include='/top/dir1/***' \
   --exclude='/top/*' \
   --exclude="*" \
   -av from/ .

おすすめ記事