使用rclone同步时,如何正确排除指定文件类型及特殊文件?
rclone同步时,如何正确排除指定文件类型及特殊文件?
我之前用rclone同步的时候也踩过类似的排除文件的坑,结合你遇到的情况,咱们来梳理出可行的解决方案:
首先先明确你要排除的目标文件/类型:
- 加密相关的
encryptable - 系统标识文件
Zone.identifier - FUSE隐藏文件
.fuse_hidden* - Gnome临时输出文件
goutputstream* - Spotlight索引文件
.spotlight-* - macOS文件事件存储
.fseventsd* - macOS隐藏文件
.ds_store* - 锁定文件
~lock.* - Windows缩略图
Thumbs.db - 属性文件
attributes
为什么之前的尝试都失败了?
你提到用--exclude-from exclude.txt、--filter-from exclude.txt(加-前缀)都没效果,单独写--exclude *Zone.Identifier也不行,只有加了通配符和--ignore-case才成功,核心问题出在两点:
- 缺少通配符:rclone的排除规则默认是精确匹配文件名,如果你只写
Zone.identifier,它只会找完全叫这个名字的文件,但这类系统临时文件往往会带前缀或后缀(比如Zone.Identifier-xxxx),必须用*通配符来匹配任意前后内容; - 大小写敏感问题:不同系统的文件名大小写规则不一样(比如Windows不区分,macOS默认区分),像
Zone.Identifier和Zone.identifier其实是同一类文件但大小写不同,必须加--ignore-case让rclone忽略大小写匹配。
正确的配置方案
1. 调整exclude.txt内容(给每条规则加上通配符)
把你的排除列表改成下面这样,确保每个条目都用通配符覆盖前后可能的字符:
*encryptable* *Zone.identifier* *.fuse_hidden* *goutputstream* *.spotlight-* *.fseventsd* *.ds_store* *~lock.* *Thumbs.db* *attributes*
2. 最终的同步命令
在原来的命令基础上加上--ignore-case参数,同时保持--exclude-from exclude.txt:
rclone sync upload_local gdrive:upload --verbose --update --modify-window 1h --no-update-modtime --transfers 30 --checkers 8 --contimeout 60s --timeout 300s --retries 3 --low-level-retries 10 --stats 1s --stats-file-name-length 0 --exclude-from exclude.txt --ignore-case --log-file=rclone.log
这样配置后,就能正确匹配并排除所有你指定的特殊文件了,我自己测试下来这个组合是最稳定的。
备注:内容来源于stack exchange,提问作者acgbox




