How to Stop Ubuntu from Automatically Deleting Temporary Files

The Vanishing Data

Linux distributions, including Ubuntu, utilize a specific directory structure for temporary data, most notably the /tmp directory. This folder is designed for applications to store transient data (like a partially downloaded file, a rendered cache, or an unzipped installer) that isn’t needed permanently. To prevent this folder from bloating and consuming your entire hard drive, Ubuntu employs a background service (often managed by systemd on modern releases) that automatically deletes files in /tmp that haven’t been accessed in several days, or completely wipes the directory upon reboot. While efficient, this can be disastrous if you rely on a temporary file for a long-running, multi-day computing task.

Preserving the Temporary Cache

To ensure your files survive indefinitely and stop Ubuntu from automatically deleting temporary files in the /tmp directory, you must alter the systemd tmpfiles configuration.

You need to override the default cleanup rules. Open your terminal by pressing Ctrl+Alt+T. The safest way to do this is to copy the default configuration file to the local override directory so your changes aren’t wiped out by a system update. Type sudo cp /usr/lib/tmpfiles.d/tmp.conf /etc/tmpfiles.d/tmp.conf and press Enter. Now, edit your local copy by typing sudo nano /etc/tmpfiles.d/tmp.conf. Look for the lines configuring /tmp (they usually start with q /tmp or v /tmp). Find the column that specifies an age (e.g., 10d for 10 days). Change that specific value to a hyphen (-). This tells the system to never expire the files based on age. Press Ctrl+O then Enter to save, and Ctrl+X to exit.

Get the best tech tips delivered straight to your inbox.

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