/tmp is the FHS location for temporary files: anything a program wants to scribble briefly, delete when it's done, or leave behind for the next reboot to sweep away. It is world-writable but has the sticky bit set, meaning users can only delete files they own—otherwise anyone could delete anyone else's scratch data.
On most modern distributions /tmp is a tmpfs mount: an in-memory filesystem whose contents vanish at reboot. This is fast, avoids wear on SSDs, and guarantees cleanup. Because it lives in memory, it competes with RAM, and very large writes can run the system into swap. For files that must survive reboot, use /var/tmp instead—same rules, but backed by disk and cleaned up less aggressively.
Temporary files are a notorious security hazard. Predictable names (/tmp/myprog.tmp) allow race conditions where an attacker pre-creates the file as a symlink to something sensitive. The portable fix is to use mktemp:
tmpfile=$(mktemp /tmp/myscript.XXXXXX)
trap 'rm -f "$tmpfile"' EXIT
echo data > "$tmpfile"
mktemp creates a file with a random suffix and restrictive permissions atomically, and the trap ensures cleanup even if the script exits abnormally. Systemd provides per-service PrivateTmp=yes, giving each daemon its own isolated /tmp to eliminate these concerns entirely.
Related terms: Filesystem Hierarchy Standard, tmpfs, Sticky Bit
Discussed in:
- Chapter 4: The Filesystem Hierarchy — /tmp — Temporary Files
Also defined in: Textbook of Linux