How can I exclude .* directories from rsync but include the .vnc directory?

It seems that a combination of --exclude '.*' and --include '.vnc' does not work:

rsync -vvrR --recursive --exclude Downloads --exclude '.*' --include '.vnc/' "pi@$host:{/home/pi,/etc/systemd/system}" $dir

The .vnc directory is not synced

[sender] hiding file /home/pi/.bash_history because of pattern .*
[sender] hiding directory /home/pi/.ssh because of pattern .*
....
[sender] hiding directory /home/pi/.vnc because of pattern .*
2

1 Answer

The order of --include and --exclude is important for rsync.

See man rsync => FILTER RULES section:

As the list of files/directories to transfer is built, rsync checks each name to be transferred against the list of include/exclude pat‐ terns in turn, and the first matching pattern is acted on: if it is an exclude pattern, then that file is skipped; if it is an include pattern then that filename is not skipped; if no matching pattern is found, then the filename is not skipped.

(accentuation by me)

That means for you:

rsync -vvrR --recursive --exclude Downloads --include '.vnc/' --exclude '.*' "pi@$host:{/home/pi,/etc/systemd/system}" "$dir"

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like