I'm using rsync with --delete to upload files to a webserver. There are files I want to exclude because they're configuration files. I'm using the "dir-merge" filter so I can have .rsync-filter files scattered through my directories, to exclude config/special files.

This seems simple, but I've been having problems!

After much investigation, my problem seems to be that if I exclude a file locally with a .rsync-filter, the file will still be deleted from the remote, unless there is already a corresponding .rsync-filter already on the remote.

What this means in practise is that if I create a .rsync-filter (locally) to exclude a file, rsync will still delete that file from the remote. But it will also copy the .rsync-filter to the remote, so the next time I try it, it will be correctly excluded.

So my question is (kind of broad) am I correct in this, and where does the man page mention this? It all seems a bit counter-intuitive to me!

Oh, and also, how is the "e" merge|dir-merge modifier useful if this is the case? (the "e" modifier excludes the merge-file from the transfer). Surely the "e" modifier makes it more likely rsync will not do what you expect?

2 Answers 2


In answer to my own question, I've failed to understand how rsync works!

Basically I thought the local rsync ran the entire process - it mostly does except that the receiver decides what gets deleted. A side-effect of this is that if per-directory merge files are being used, the receiver will be unaware of these until the merge files have themselves been uploaded.

My initial thought was to first run rsync without delete, to get the merge files in sync, and then re-run rsync with delete to ensure things got run correctly. But it turns out --delete-after solves this.

Another thing that caused me confusion is, if you use --delete-after and --dry-run then it will still appear to delete excluded files because, it being a dry-run, the receiver is still unaware of the filter rules in the (as yet) un-synchronised merge files.

Finally, the "e" modifier on dir-merge would exclude the merge files from being uploaded, and thus I conclude it's not a good plan to use it at the same time as --delete!

  • 1
    I was trying to determine whether --dry-run could effectively be used with per-directory merge files and --delete, and this is the only answer I was able to find regarding that. Unfortunately, it was well down in the Google results, so hopefully my repeating some of those terms in this comment will increase its page rank.
    – dg99
    Nov 7, 2017 at 18:36

You don't want to exclude those files, you want to protect them. I.e. don't use - filename but use P filename.

  • Protect isn't the answer. Exclude is actually a Hide and Protect. The Hide part means the sender will not include the specified file when it generates it's file-list. The Protect part means the receiver will not delete the specified file. So if I only Protect a file, it will indeed stop the receiver from deleting it, but it won't stop the sender from uploading a new version of that file.
    – Peter Ryan
    Sep 28, 2014 at 22:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .