In a build script I want to create a temporary file that has a unique generated name, then write some data to it, and then rename that file to its final name (the reason for this procedure is that I want the renaming to happen (mostly) atomic).
But if I use mktemp
, the new file will have very restrictive permissions:
Files are created u+rw, and directories u+rwx, minus umask restrictions.
... and these permissions will be preserved when the file is renamed. However, I want the resulting file to have "normal" permissions; that is, it should have the same permissions as files created by touch
or by a shell redirection.
What is the recommended way to achieve this? Is there a (common) alternative to mktemp
; or is there a simple and reliable way to change the file permissions to the normal umask
permissions afterwards?
chmod
on it, can't you? https://unix.stackexchange.com/a/249850 – Artem S. Tashkinov May 25 '21 at 09:49