Part II · Your system
13.2 /tmp vs /var/tmp
alsotmp/tmp/var/tmptmpfsmktemptemporary files
TL;DR
/tmp: short-lived scratch files. Often in RAM (tmpfs) and emptied at every boot./var/tmp: temporary files that must survive a reboot. Always on disk.- Both are cleaned by age. With systemd's default settings, files unused
for 10 days leave
/tmp, and 30 days for/var/tmp. - In scripts, create temporary files with
mktemp, never with a fixed name.
mktemp # a new private file in /tmp
mktemp -d # a new private folder
On your machine
$ atfq 13.2 /tmp in RAM (tmpfs), emptied at every boot · 7.0 GiB free (88%) · inodes 0% used /var/tmp on disk (btrfs), part of / · 120.0 GiB free (30%)
An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.
Pitfalls
- A tmpfs
/tmplives in RAM: a huge file there competes with your apps for memory. tmpfs is capped, at half the RAM unless set otherwise. - A fixed name like
/tmp/myapp.logis a security hole: another user can create that name first, as a link to one of your files. - Everyone can write to
/tmp, yet nobody can delete other people's files there: that's the sticky bit (see 15.2). - Don't keep anything you need in
/tmp: it may be gone after a reboot.
Deep dive 2 questions
Why are there two temporary folders?
The Filesystem Hierarchy Standard gives them different promises: /tmp may
be cleared at boot, /var/tmp is kept between reboots. Programs that need
large or long-lived temporary data, such as a package build or a text
editor's recovery files, use /var/tmp.
Why did distros move /tmp to RAM?
RAM is faster than any disk, writes to RAM don't wear out an SSD, and
emptying it at boot is free. Fedora made a tmpfs /tmp the default in
release 18 (2013), and Debian in release 13 (2025).
The cost is memory: big files in /tmp take RAM. tmpfs can move them to
swap under pressure, but a machine without swap has nowhere to put them.