Table of Contents
Purpose of `/tmp`
The /tmp directory is a special place in the Linux filesystem used for temporary files. Programs, scripts, and sometimes users store data here that is only needed for a short time, such as intermediate results, temporary downloads, or lock files.
Most systems treat /tmp as a shared scratch space. Any program can create files here without asking an administrator, which makes it very convenient for short lived data. Because of this, it is normal to see /tmp full of strange names and files you do not recognize.
Important rule: Never store anything important or long term in /tmp. You must always assume that anything in /tmp can disappear at any time.
Lifetime of files in `/tmp`
Files inside /tmp are not guaranteed to stay. Many Linux systems clean /tmp automatically. Some remove files from /tmp at every reboot, others remove files if they are older than a certain age, for example 10 days.
On some distributions /tmp is stored in memory using a tmpfs filesystem. In that case everything in /tmp is definitely lost when you restart or power off the system, because the content lives only in RAM and is not written to disk.
You should therefore think of /tmp as a workspace that the system is free to wipe whenever it chooses. If you need to keep a file, copy or move it to your home directory or another persistent location.
Permissions and security considerations
By convention /tmp is world writable. This means any user on the system can create files there. At the same time, the system uses a special permission bit so that other users cannot peek into or delete each other’s files.
If you check /tmp with a command like ls -ld /tmp, you will usually see something similar to:
drwxrwxrwt 10 root root 4096 Jan 7 10:00 /tmp
The final t is the “sticky bit”. It changes how deletion works inside that directory.
Sticky bit rule: In a directory with the sticky bit set, such as /tmp, a file can usually be deleted or renamed only by its owner, the directory owner, or the superuser, even if the directory is world writable.
This rule protects users from removing each other’s temporary data in /tmp, while still allowing everyone to create files there. It is an important part of basic security on multiuser systems.
When programs use `/tmp`
Many applications and tools use /tmp automatically. You may not even notice it, because they create hidden or random named files and remove them when they are done. Typical uses include:
Text editors that create backup copies or swap files while you are editing, browsers that keep partial downloads or cache fragments, archive tools that unpack files temporarily before installing, and scripts that need a place to store intermediate results.
As a user, you can also use /tmp for quick tests and throwaway work. For example, if you need to unpack a large archive just to look inside for a moment, you can place it in /tmp so you do not clutter your home directory. Just remember that the system may erase it at the next reboot or cleanup.
Good practices when using `/tmp`
Although /tmp is designed for temporary files, you should still treat it with some care.
First, do not rely on /tmp for anything you might need later. If a program saves something important there, copy it elsewhere as soon as you realize it has value. Second, avoid filling /tmp with huge files, especially on systems where /tmp is backed by memory. Large files in /tmp can reduce available RAM or disk space and can slow down the system.
If you want to create your own temporary files or directories safely from the command line or in scripts, prefer commands that generate unique names and correct permissions, such as mktemp. This avoids name collisions with other programs that use /tmp at the same time.
Finally, remember that /tmp is shared by all users on the machine. Even with the sticky bit, you should not place private or sensitive information there unless it is protected by appropriate file permissions or encryption. The directory itself is public, and its content is meant to be temporary and disposable.