Once /tmp ideally should be reserved for the system, where can a user create temporary files safely?
Asked
Active
Viewed 1,473 times
3
1 Answers
7
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.
Gilles 'SO- stop being evil'
- 829,060
mktempand leave the details for the implementation to decide? – frippe Nov 09 '21 at 09:46/tmpideally be reserved for the system? – ilkkachu Nov 09 '21 at 10:22/tmpwas created exactly with multi user environment in mind. – Artem S. Tashkinov Nov 09 '21 at 10:57/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. – Bib Nov 09 '21 at 11:08