How to make rsync preserve timestamps of unchanged files

12,134

The -c option seems to do what I want. The performance penalty is not an issue in my case.

Share:
12,134
Petri Lehtinen
Author by

Petri Lehtinen

Coding Python, C and Javascript for fun and profit.

Updated on June 07, 2022

Comments

  • Petri Lehtinen
    Petri Lehtinen almost 2 years

    I use a static website generator that generates all the files in the website on each run. After generating the files, I use rsync to copy the content in place.

    To allow better caching, I'd like rsync to not modify the timestamp of those files in the destination that have not changed. Is it possible?

    EDIT: To make it clear, timestamps of all the source files are always newer than the timestamps of the destination files.

  • Petri Lehtinen
    Petri Lehtinen about 13 years
    Yes, the source file timestamp is always changed to the "now".
  • MarcB
    MarcB about 13 years
    In that case, try using --size-only so that it skips the new files (assuming they are the same size)... its a bit dangerous though, can have unintended consequences. Using it in conjunction with -c is a bit better, but its slow.
  • Pungs
    Pungs about 10 years
    -t will be better in your case
  • Petri Lehtinen
    Petri Lehtinen over 9 years
    I don't think so, because the timestamps of source files are always newer than those of the destination files even though the files contents haven't changed.
  • ishmael
    ishmael over 8 years
    The -c option works. One thing to note though: if you don't want the modification times to change, be sure not to use the -a option, as it silently invokes -t, which means "preserve modify times", i.e. "overwrite the modification times of the remote files with the modification times of the local files."
  • knowname
    knowname over 2 years
    @ishmael alternatively you can use -a (--archive) in combination with --no-times