I can't find a solution to do the following with rsync on Linux:

  • Compare two folders
  • When found two identical files on the same root position on both source tree and target tree, with same name, but different timestamp or size:
  • Instead of updating the target file (less size or older timestamp) with the source on (newer or bigger size), either by appending the missing chunks to the content (using -u), or replacing the Whole file (using -W), I'd like to have it: copying it, to the same tree position, with a name prefix or suffix.

There has been a solution to avoid losing the older file if overridden, by copying them into a third folder, but I think copying them to the same place on target, and renaming them, keeping the old one there too, would be of a better context by keeping the new files locations.

Here is how I want it to work:

enter image description here


If I understand you correctly, you're wanting to do versioning of files. This was discussed in a previous question, with the exception that you're wanting to work on an entire directory. It's pretty easy to do (taken from @Sridhar-Sarnobat's answer):

rsync -ab --suffix=`date +'.%F_%H-%M-%S'` ${SRC}/ ${DEST}
  • Thank you @ErikF for pointing me out to that answer. I tried this code: rsync -zrvt --progress --backup --suffix=date +'.%F_%H-%M' /home/office1/Music/rsync-test1/target/ /home/office1/Music/rsync-test1/source but it did nothing. However, I added a figure to my question, so it becomes more clearer. Please see why the code didn't work? – OpenSourceMan Dec 31 '17 at 5:02
  • Did you accidentally swap target and source? Also, I did some testing and found that the file in the destination is the one that's renamed, not the file from the source (for example updating 1.txt in the source will make it the new 1.txt, and the matching file in the destination becomes 1.txt.2017-12-30_22-22-50): this doesn't quite match what you were looking for in the original question, and actually wasn't what I had expected! – ErikF Dec 31 '17 at 5:59
  • This code needs to be changed to make the incremental suffix value (as my example) - or just the time-stamp, as in the example code - to do that to the "copied source file" only, leaving the destination file intact. Thanks for your input! – OpenSourceMan Dec 31 '17 at 6:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.