Once /tmp ideally should be reserved for the system, where can a user create temporary files safely?
1 Answer
The right place to create temporary files¹ is, and has always been, the directory indicated by the TMPDIR environment variable, with /tmp as a fallback. If a system has a location for temporary files other than /tmp, setting TMPDIR is how it advertises this location.
In a shell script, that's ${TMPDIR:-/tmp}, although typically you should call the mktemp command and let it decide.
¹ Of course, I'm not talking about temporary files that need to be in a specific directory, for example because they'll be atomically moved into place once their content is ready.
mktempand leave the details for the implementation to decide?/tmpideally be reserved for the system?/tmpwas created exactly with multi user environment in mind./var/tmpwas the place for users to store temporary files. That directory also tended to be preserved across reboots, whereas/tmpwas wiped, especially since it was a virtual mount. That no longer seems to happen in many places.