devutils/ATFQ/book ATFQ git

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

alice@laptopexample
$ 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

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.

Commands
mktemp
Paths
/tmp /var/tmp
See also
14. Disk
15.2 setuid, setgid and sticky bit
13.1 The hierarchy in 2 minutes