gpt4 book ai didi

linux - 复杂的 rsync 过滤(包括和排除)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:40:29 25 4
gpt4 key购买 nike

我得到的目录和文件看起来像这样

/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 的日程文件夹?

最佳答案

如果我理解正确的话,你需要在你的命令中添加选项--prune-empty-dirs(简而言之,-m)。这些目录与排除其子项的排除规则不匹配,因此默认情况下会复制它们。 -m 可以防止这种情况。如果要防止其他文件被复制,则必须为它们添加特定的排除规则。例如1.txt2.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/

关于linux - 复杂的 rsync 过滤(包括和排除),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43331235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com