11

i use rsync -avh

I just want to know that if the file on destination already exists does the rsync overwrite the new file or not

1 Answers1

17

If the file contents are the same, then no; it will merely fudge the metadata to match. If the file contents differ then the file will be overwritten; use --ignore-existing to change this behavior, or -u to use a different, sane behavior.

Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
  • 5
    So it actually replaces the file, not update? If that file is hard-linked, the the other link is unaffected? – Mark Jul 31 '15 at 15:56
  • 2
    @Mark Asking the important question here. – Syncopated May 25 '18 at 12:41
  • 1
    It looks like you are correct that it replaces the file by default, thus "breaking" the hard link. I just noticed an --inplace option: "instead of the default method of creating a new copy of the file and moving it into place when it is complete, rsync instead writes the updated data directly to the destination file." "Hard links are not broken. This means the new data will be visible through other hard links to the destination file." – Tyler Rick Nov 08 '21 at 18:46