Table of Contents
/tmp
/tmp is the system-wide directory for temporary files. Any process can create files here. The kernel cleans it on reboot; many distributions also run a periodic cleanup of files older than a few days. On most modern systems /tmp is a tmpfs mount, meaning it lives entirely in RAM (and swap) rather than on disk — writes to /tmp never touch the filesystem and are lost on reboot.
# common uses mktemp # create a unique temporary file, returns the path mktemp -d # create a unique temporary directory mktemp /tmp/proc.XXXXXX # XXXXXX is replaced with a random suffix
/tmp is world-writable: every user and process can create files in it. To prevent one user from hijacking another's temporary files, the sticky bit is set on the directory (drwxrwxrwt). The sticky bit means that only the file's owner (and root) can delete or rename it, even though everyone has write permission on the directory itself.
For files that should survive across reboots, use /var/tmp instead. The convention is that /tmp can be cleared at any time, while /var/tmp persists until explicitly removed. Daemons and long-running services should use /var/tmp for work files they expect to pick up after a restart.
