have cp copy to temp file then mv
by Skaperen from LinuxQuestions.org on (#5458W)
the cp command copys normally by opening the target file directly, truncating it as it opens, then copying. this has strange effects when copying to a file another process is currently reading. what i have to avoid that is a script to copy to a temporary file first, then move the temporary into place.
i would like to know if there is an option to get cp to do that.
i do not want to remove it first (--remove-destination) as some process may try to open it at that instant. it should try to open the destination file with O_EXCL and if it gets EEXIST then do the temporary thing. my script can't do it quite right, although maybe it is better to not have a new file to initially exist empty.


i would like to know if there is an option to get cp to do that.
i do not want to remove it first (--remove-destination) as some process may try to open it at that instant. it should try to open the destination file with O_EXCL and if it gets EEXIST then do the temporary thing. my script can't do it quite right, although maybe it is better to not have a new file to initially exist empty.