Is /tmp guaranteed to exist

tmp

Do I need to check & create /tmp before writing to a file inside of it?
Assume that no one has run sudo rm -rf /tmp because that's a very rare case

Best Answer

The FHS mandates that /tmp exist, as does POSIX so you can rely on its being there (at least on compliant systems; but really it’s pretty much guaranteed to be present on Unix-like systems). But you shouldn’t: the system administrator or the user may prefer other locations for temporary files. See Finding the correct tmp dir on multiple platforms for more details.