Is it possible to change the name of the destination file (add some timestamp as a prefix) when copy is done by rsync ?

For example, I can use the following command to change the name of the destination file using suffix:

rsync --append  -arzvv --backup --suffix='_2015_09_10' /path/to/src/file /path/to/dst

But I would like to attach the time stamp as a prefix, so in the destination we will have some thing like: 2015_09_10_file instead of file_2015_09_10.

  • 1
    Doubt it -- how would rsync know which files it had copied?
    – Jeff Schaller
    Oct 13, 2015 at 1:01
  • Could you add an example of what you have in mind? Oct 13, 2015 at 2:06
  • 3
    Your --suffix is applied to the backup copy of an existing file, not to the new file, which cannot be renamed. You will have to do the rename after the rsync with a separate command. An alternative is to use a destination directory which is the date, so the file keeps the same name.
    – meuh
    Oct 13, 2015 at 6:12

3 Answers 3


Actually you can, but kind of hacky.. and only as suffix.

As you have read in the comments, --suffix is for backups of overwritten files. So you rsync the same files from source to destination, kind of forcing rsync to overwrite (-I) - but only if the source file is (-u) newer (which it never is) and using the -b, --backup option and define a backup directory and a suffix.

rsync -Iu --backup --suffix='_2015_09_10' --backup-dir=/path/to/dst /path/to/src/file /path/to/src/file


Rsync cannot do this at the level of individual files, but has some support for doing whole trees. E.g.:


There are three options:

  • --compare-dest=DIR where only new files are created in the new directory. This is probably not what you want because you'd have to list all the previous version directories.
  • --copy-dest=DIR where unchanged files are copied from DIR to the destination rather than transferring them from the source.
  • --link-dest=DIR is the same, but uses much less disk space on the destination because it does not duplicate the file contents.

You use it like this:

rsync -a --link-dest=/path/to/dst-$YESTERDAY /path/to/src /path/to/dst-$TODAY

It is straightforward to rename individual files rsync transfers:

rsync /path/to/original_name.txt /path/new/my_new_file_name.txt

Just specify the filename in the destination path, and that becomes the new filename. In OP's case, this doesn't help because they want to use part of the existing filename to rename the a whole bunch of files. But I'm adding this to make the Q/A more generally helpful.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .