rsync 仅包含目录模式
rsync include only directory pattern
我只想包含名为 *cache*
的目录及其下的所有文件和子目录。
rync --include --exclude
怎么写?
source dest
├── a │
├── b ├── b
│ └── d │ └── d
│ └── e │ └── e
│ └── cache │ └── cache
├── c ├── c
│ └── f │ └── f
│ └── npm_cache │ └── npm_cache
├── g ├── g
│ └── cache_stores │ └── cache_stores
├── h ├── h
│ └── cache │ └── cache
│ └── i │ └── i
│ └── j │ └── j
└── k │
└── l │
这应该有效:
--include='*/'
--include='*cache*/**'
--exclude='*'
--prune-empty-dirs
也就是说:
- 包括所有文件夹(这是在其中搜索所必需的)。
- 包含父目录名称中带有 "cache" 的所有文件。
- 排除其他一切。
- 删除所有已复制但结果不包含缓存的文件夹。不幸的是,这也会删除缓存目录中的所有空文件夹,但希望这对您来说并不重要。
我已经接受了 ams 的回答,但是如果您不知道 rsync --include --exclude
语法(我不知道),请先获取带有 find
的显式文件列表。
cd source
find . | grep /.*cache.*/ | rsync --files-from=- source dest
我只想包含名为 *cache*
的目录及其下的所有文件和子目录。
rync --include --exclude
怎么写?
source dest
├── a │
├── b ├── b
│ └── d │ └── d
│ └── e │ └── e
│ └── cache │ └── cache
├── c ├── c
│ └── f │ └── f
│ └── npm_cache │ └── npm_cache
├── g ├── g
│ └── cache_stores │ └── cache_stores
├── h ├── h
│ └── cache │ └── cache
│ └── i │ └── i
│ └── j │ └── j
└── k │
└── l │
这应该有效:
--include='*/'
--include='*cache*/**'
--exclude='*'
--prune-empty-dirs
也就是说:
- 包括所有文件夹(这是在其中搜索所必需的)。
- 包含父目录名称中带有 "cache" 的所有文件。
- 排除其他一切。
- 删除所有已复制但结果不包含缓存的文件夹。不幸的是,这也会删除缓存目录中的所有空文件夹,但希望这对您来说并不重要。
我已经接受了 ams 的回答,但是如果您不知道 rsync --include --exclude
语法(我不知道),请先获取带有 find
的显式文件列表。
cd source
find . | grep /.*cache.*/ | rsync --files-from=- source dest