/tmp
temporary files/tmp is shared scratch space. Programs put files here that they need for a moment — a download half-finished, an archive being unpacked. Every user can write to it, and the system is free to empty it.
Use it freely. Do not expect to find it again.
Why it exists
Every directory at the top of the tree is there for a reason. This is the problem /tmp solves.
A program should not need special rights just to save a working file. /tmp is the one directory on the system open to every user for that.
Although everyone can write here, the sticky bit means a file can be deleted only by its owner or root. One user cannot remove another’s files.
What you find inside
Not everything, but the entries worth recognising. Each is marked as a directory, a file, a link or a device.
- systemd-private-…directoryA private temporary directory that systemd gives to one service.
- .X11-unixdirectorySockets used by the graphical display.
- tmp.Xa4kQ9fileA file created by mktemp, with a random name.
- ssh-XXXXXXdirectoryAn SSH agent’s socket, for the length of a session.
At the terminal
Four commands that show what this directory is doing on a real machine.
ls -ld /tmpShow the permissions: drwxrwxrwt. The final t is the sticky bit.
mktempCreate a temporary file with a name nobody can guess, and print the name.
mktemp -dThe same, for a temporary directory.
df -h /tmpSee whether /tmp is on a disk or held in memory.
Handle with care
What goes wrong here, and what someone securing or attacking the machine looks at.
A script that writes to /tmp/output can be tricked by another user who creates that name first, as a link to a file they want overwritten. Use mktemp.
Because anyone can write here, tools dropped by an attacker often land in /tmp or /dev/shm. Unexpected executables in either deserve a look.
/var/tmp is kept across reboots and cleaned less often. /tmp may be emptied without warning.