Sample Header Ad - 728x90

How to create a temporary file that has "normal" permissions?

4 votes
2 answers
4298 views
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?
Asked by oliver (468 rep)
May 25, 2021, 09:18 AM
Last activity: May 25, 2021, 03:05 PM