rsync switch to only compare timestamps

Is there a way to let rsync only compare timestamps of files, and ignore their contents? That includes ignoring the file size. Just the timestamp. Nothing but the timestamp.


Solution 1:

Rsync cannot compare files using only the timestamp. It will always compare the file size regardless, and if you specify -c it will also compare the file's checksum.

The whole point of rsync is to make one file tree match another. If a file in one tree has a different size to the same file in the other tree then they must, logically, differ. So rsync will copy it. Regardless.

If you want to copy the files in the way you want you will have to adopt a different method using different tools.

If you only want to copy files that have changed since a know date (say, the last time you copied the files) you can use find's -cnewer flag. The following little script will find files that have changed since the last time it was run:

find /path/to/files -cnewer /tmp/lastSync
touch /tmp/lastSync

The -cnewer compares the file's modified time to that of the specified file (/tmp/lastSync in this example):

-cnewer file
   File's  status  was last changed more recently than file was modified.  
   If file is a symbolic link and the -H option or the -L option is in 
   effect, the status-change time of the file it points to is always used.

The touch command will update the timestamp of /tmp/lastSync to reflect the fact that the script has just been run so that subsequent runs of the script use the current time as it's time base.

The output of the find command can then be used to specify the files to copy to the destination using whatever method you like (cp, scp, whatever).

Solution 2:

The following command line does the job :

rsync -avu src/ dst/

From the man page about -u, --update

This forces rsync to skip any files which exist on the destination and have a modified time that is newer than the source file. (If an existing destination file has a modification time equal to the source file’s, it will be updated if the sizes are different.)