i'm looking for a command that can sync dir1 and dir2, without swapping and deleting the files in those directories.
The current command i'm using is
rsync -av --delete dir1 dir2which deletes files that belong to dir2 but not dir1. In other words, it will create a duplicate dir1 in a fast way.
say, for example, i add 5 files to dir2 and would like to preserve the order of the command rsync. i want to sync it back to dir1. what options of rsync are available that can help me doing this?
assume i don't want to delete any files in both directories.
21 Answer
You can you this command
if [ -n "$(rsync -anv --delete dir1/ dir2/ | grep deleting)" ]; then \ rsync -av dir2/ dir1/; else rsync -av dir1/ dir2/; fi