I have two source folders I would like to keep synced into the same destination folder. I usually give two separate commands:

rsync -auP --delete-before "/source1/" "/detination/"
rsync -auP --delete-before "/source2/" "/detination/"

However, when giving the 2nd command, files that were copied from source1 since they are of course not present in source2 they are being removed because of the --delete-before option.

Do you know a way to keep a 1:1 copy of the two sources both syncing into the same destination? I know I could do something like this to resolve:

rsync -auP --delete-before "/source1/" "/detination/source1/"
rsync -auP --delete-before "/source2/" "/detination/source2/"

But just wanted to check if I can still get the result as mentioned earlier.

  • How are you proposing to handle files that exist in both source directories?
    – Kusalananda
    Sep 25, 2021 at 9:53

1 Answer 1


Rsync has no history. There's no way to automatically say "make it look like treeA, but don't delete files that exist in treeB".

Your question asks for a 1:1 copy of the trees, but it sounds like maybe you want a merged copy instead.

You could do something a bit more complex like:

  • rsync treeB and record all the transferred files (use -i)
  • post-process the transferred files into a list of just filenames
  • rsync treeA and exclude all the files from earlier

Now if any file is in both, it will be the treeB copy. If any file is in only one, it will be in the directory. The drawback is that any file that is only in treeA will constantly be deleted and then re-copied on every run.

You must log in to answer this question.

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