How to Stop Ubuntu from Automatically Deleting Temporary Files

The Missing Data

Ubuntu Linux uses a specific directory, `/tmp`, to store temporary files created by applications during runtime. By strict system design, this folder is mounted as a temporary filesystem (`tmpfs`), which exists entirely in your computer’s RAM. Because it is stored in volatile memory, Ubuntu automatically completely wipes and deletes every single file inside the `/tmp` directory the moment you shut down or reboot your computer. While this keeps the system clean, it can be disastrous if you are a developer compiling a massive project that stores intermediate files in `/tmp`, and you suffer an unexpected power loss or need to reboot halfway through the process.

Persisting the Temp Folder

To preserve your intermediate data across reboots and stop Ubuntu from automatically deleting temporary files, you must stop the system from mounting `/tmp` in RAM and force it to use your physical hard drive instead.

Open your terminal (Ctrl+Alt+T). The service responsible for mounting the temporary RAM disk is controlled by systemd. You need to mask this specific service, which completely disables it from running at boot. Type the following command and press Enter: sudo systemctl mask tmp.mount. You will be prompted for your administrator password. This command creates a symlink pointing the service file to `/dev/null`, effectively neutralizing it. Once you reboot your machine, Ubuntu will no longer create a RAM disk for `/tmp`. Instead, it will just use the standard `/tmp` folder located on your physical hard drive (usually an ext4 partition). Any files placed in there will now survive a reboot indefinitely.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.