What is the difference between /tmp and /var/tmp?
Both are for temporary files. /tmp is meant for short-lived data and is often cleared at reboot (or is even held in RAM), while /var/tmp is for temporary files that should survive a reboot.
Explain it simply
/tmp is a scrap-paper pad on your desk; it is cleared out regularly. /var/tmp is a drawer for papers you want to keep for a few days, even if you shut the office overnight.
On many distributions /tmp is cleared at every boot, and some (Fedora, Arch) mount it as tmpfs, which lives in RAM. Ubuntu and Debian have historically kept it on disk, cleaning old files on a schedule. /var/tmp is kept across reboots, and systemd cleans entries there after about 30 days by default.
Both folders are world-writable, and both use the sticky bit so one user cannot delete another's files. Never store anything important in either place.
Example
ls -ld /tmp /var/tmp
# drwxrwxrwt 12 root root 4096 ... /tmp
# drwxrwxrwt 4 root root 4096 ... /var/tmp
df -h /tmpThe final t in drwxrwxrwt is the sticky bit.
What to say in the interview
"/tmp is for short-lived scratch files, usually cleared at boot and sometimes in RAM. /var/tmp is for temporary data that must survive a reboot. Both are world-writable with the sticky bit set, and neither is a place for data you cannot lose."
Common mistakes
- Assuming /tmp is always cleared at reboot; it depends on the distribution.