Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 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).

share|improve this answer
1  
It seems to compare file sizes by default. I don't want it to care about what the file contains. –  user67194 Mar 20 '11 at 20:42
1  
Matt already addressed that question in his answer and clearly the answer is "no". Rsync is a tool that cares about contents, even if it's willing to just assume same contents when the dates match. If you don't like that, you need a different tool. –  Peter Hansen Jul 4 '11 at 11:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.