Rsync Temporary File Extension – How to Set

filenamesrsync

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?

Best Answer

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"
Related Question