我的目录和文件看起来像这样
/1.txt
/2.txt
/3.txt
/20170407_000000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
/20170407_120000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
/20170408_000000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
/20170408_120000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
/20170409_000000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
/20170409_120000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
/20170410_000000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
/20170410_120000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
/20170411_000000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
/20170411_120000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
/20170412_000000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
/20170412_120000
/config
file1.txt
/logs
file1.txt
/nav
file1.txt
/schedule
file1.txt
file2.txt
file3.txt
/soh
file1.txt
/tracks
file1.txt
我只想复制20170409 _ * / schedule,20170410 _ * / schedule,20170411 _ * / schedule文件夹和内容。
这主要有效:
rsync -avhr --progress --include="/20170409_*/schedule/" --include="/20170410_*/schedule/" --include="/20170411_*/schedule/" --exclude="/*/*" /source/dateTimeDirectories/ /destination/dateTimeDirectories/
然而,这也复制了以下内容:
1.txt
2.txt
3.txt
20170407_000000/
20170407_120000/
20170408_000000/
20170408_120000/
...
20170412_000000/
20170412_120000/
如何省略文件和我没有包含的dateTimeFolders,只获取我所包含的dateTimeFolder的日程安排文件夹?
答案 0 :(得分:1)
如果我理解了这种情况,您需要在命令中添加--prune-empty-dirs
选项(简称-m
)。这些目录与排除其子项的排除规则不匹配,因此默认情况下会复制它们。 -m
阻止了这一点。如果要阻止复制其他文件,则必须为它们添加特定的排除规则。例如,1.txt
可以排除2.txt
,--exclude=/*.txt
等文件。总而言之,您的命令应如下所示:
rsync -avhr \
--progress \
--prune-empty-dirs \
--include="/20170409_*/schedule/" \
--include="/20170410_*/schedule/" \
--include="/20170411_*/schedule/" \
--exclude="/*.txt" \
--exclude="/*/*" \
/source/dateTimeDirectories/ \
/destination/dateTimeDirectories/