Using rsync to keep two directories in sync

I have two directories with (mostly) the same content that I want to keep in sync. Specifically I want to make sure that the newest version of each file is synced to the other directory. This allows me to update a file on either side, and that version will propagate to the other. You can do this with a bi-directional rsync command:

rsync --update -av /dir/a/ /dir/b/
rsync --update -av /dir/b/ /dir/a/

Using --update tells rsync to skip files on the receiving side that are newer. If you sync a -> b and then b -> a you end up with both locations having the newest copy of each file.

Tags:
All content licensed under the Creative Commons License