With RSYNC, how do includes and excludes combine?

2019-04-29 08:05发布

问题:

I want to rsync everything in /Volumes/B/, except for Cache directories, which I want to exclude globally. Also, I don't want to rsync any other /Volume/

I have the following exclusion file:

+ /Volumes/B/***
- Cache/
- /Volumes/*

The first and 3rd line seem to work correctly, except that rsync also picks up all Cache dirs under /Volumes/B/... ( /Volumes/B/***/Cache/ )

What am I missing?

回答1:

rsync reads the exclude file top down when traversing the directories.
When it visited the Caches dirs, rsync acted on the first matching pattern.
The first matching pattern was "+ /Volumes/B/*", so Cache was included.

The rule is: When having particular subdirectories, put them first.

Here 's a simple step by step explanation.



标签: rsync