I am having difficulties finding how Rsync "chooses" the extension for the temporary file created while copying the file if I don't use the --inplace option.

Example : I want to copy sourceDirectory/myFile.txt into targetDirectory/ with Rsync.

While copying myFile.txt into targetDirectory/ Rsync will create a file named .myFile.txt.W4zvLi in targetDirectory/.

Then Rsync will rename .myFile.txt.W4zvLi into myFile.txt.

The question is how why Rsync uses the W4zvLi extension and why it seems to change each time I execute the Rsync program?


rsync uses the mktemp(3) POSIX function to generate a unique temporary file name. You pass a template string to the mktemp function, and it will return a file name with any X characters in the template replaced by a random character.

In particular, rsync passes .XXXXXX to mktemp. If you want to try it out from the command line you can use the mktemp(1) binary like so:

mktemp -u "/tmp/foo.XXXXXX"

man rsync:

Beginning with rsync 3.1.1, the  temp-file  names  inside
              the specified DIR will not be prefixed with an extra dot (though
              they will still have a random suffix added).
  • Explaining that the extension is chosen randomly might be a good idea. – terdon Nov 7 '16 at 14:07
  • Any clue about how the "random" suffix is calculated? – Jean-Paul Goodwin Nov 7 '16 at 14:08
  • The clue is in the source of rsync and kernel. – Ipor Sircer Nov 7 '16 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.