0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rsyncで一部のサブディレクトリの中身だけをコピー

0
Posted at

一言で書くと:末尾がaかcで終わるディレクトリにマッチさせたいときに--include='*{a,c}/'だとダメで--include='*'{a,c}'/'とする必要があるという話。

多階層になっているフォルダから一部のファイルだけをrsyncしたいとする。rsyncの--include、--excludeが複雑怪奇なのはよく知られている[Link]が、試行錯誤が必要だったパターンがあったのでメモ。

次のようなフォルダ構成から、hoge_a/f1とhoge_c/f1の下のpngファイルだけをrsyncしたいとする。ディレクトリとしてはhoge_bもあるのがポイントで。

project
│   ...
│
└───hoge_a
│   │   ...
│   │
│   └───f1
│   |   │   fuga.png
│   |   │   ...
│  ...
│
└───hoge_b
│   │   ...
│   │
│   └───f1
│   |   │   piyo.png
│   |   │   ...
│  ...
└───hoge_c
│   │   ...
│   │
│   └───f1
│   |   │   foo.png
│   |   │   ...
│  ...

サフィクスがaとcのディレクトリだけ対象にしたいので、次のように*{a,c}でフィルタリングしようとしてもうまくいかない。

$ rsync -ahv --include='*{a,c}/f1/*.png' \
             --include='*/' \
             --exclude='*' \
             remotehost:~/project/ ~/project/

次のように{a,c}をクオーテーションの外に書くと無事コピーが開始される。理由は知らない。

$ rsync -ahv --include='*'{a,c}'/f1/*.png' \
             --include='*/' \
             --exclude='*' \
             remotehost:~/project/ ~/project/
0
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?