# /tmp and temporary files

> What /tmp and /var/tmp are for, when Linux cleans them, and how systemd-tmpfiles controls their age limits.

/tmp is the directory for temporary files that programs need only for a short time. /var/tmp is for temporary files that should survive a reboot. On many distributions /tmp is cleared at boot or is a tmpfs in memory, and old files in both are removed by systemd-tmpfiles.

## /tmp versus /var/tmp

The Filesystem Hierarchy Standard says programs must not assume files in /tmp are kept between program runs, while /var/tmp is preserved across reboots. Both are writable by all users and have the sticky bit, so users can delete only their own files.

## Automatic cleaning

systemd-tmpfiles reads rules from tmpfiles.d directories, for example /usr/lib/tmpfiles.d/tmp.conf, which commonly sets an age of 10 days for /tmp and 30 days for /var/tmp. The cleaning runs daily through systemd-tmpfiles-clean.timer.

## tmpfs

When /tmp is mounted as tmpfs, its files live in RAM and swap and disappear at every reboot. 'findmnt /tmp' shows whether it is a tmpfs.

## How to check and clean /tmp

1. Check its size: sudo du -sh /tmp /var/tmp
2. See whether it is in memory: findmnt /tmp
3. Run the configured cleanup now: sudo systemd-tmpfiles --clean
4. List old files before deleting anything by hand: sudo find /tmp -type f -atime +10

## Cautions

- Deleting files in /tmp that a running program still uses can make it fail; prefer the systemd-tmpfiles cleanup or a reboot.
- Do not delete sockets and lock files of running services.

## Sources

1. [tmpfiles.d(5) manual page](https://man7.org/linux/man-pages/man5/tmpfiles.d.5.html)
2. [Filesystem Hierarchy Standard 3.0: /tmp](https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s18.html)

Last reviewed: 2026-10-08
URL: https://wiki.raincleaner.eu/linux/tmp-directory
