The Vanishing /tmp Directory
In Ubuntu Linux, the `/tmp` directory is designed for exactly what its name suggests: temporary files. By default, the systemd initialization process is configured to completely wipe the contents of this directory every time you reboot your computer. Furthermore, background cron jobs often sweep through and delete files in `/tmp` that haven’t been accessed in a certain number of days. If you are using `/tmp` to store a large dataset while you write a complex script over several days, this automatic deletion will silently destroy your work overnight.
How to Prevent Automatic /tmp Deletion on Boot
To stop systemd from clearing the directory when you restart your computer, you must override the default `tmpfiles.d` configuration.
1. Open your terminal.
2. You need to copy the default configuration file to the local override directory. Run this command: sudo cp /usr/lib/tmpfiles.d/tmp.conf /etc/tmpfiles.d/
3. Open the copied file in a text editor with root privileges: sudo nano /etc/tmpfiles.d/tmp.conf
4. Look for the lines that begin with the letter D or q concerning the `/tmp` path. For example, you might see D /tmp 1777 root root - or similar.
5. To disable the automatic cleanup, you can either comment out the line by adding a `#` at the very beginning of the line, or change the time-age parameter at the end of the line (e.g., change `10d` to `-`).
6. Press Ctrl + O to save, and Ctrl + X to exit.
The Better Solution: Use Your Home Directory
While overriding systemd works, fighting the operating system’s core design is generally a bad idea. The `/tmp` directory is fundamentally volatile. If you have files that you need to survive a reboot, you should absolutely not store them in `/tmp`. Instead, create a dedicated temporary workspace inside your own user directory (e.g., `mkdir ~/temp_workspace`). Files stored in your home directory are never automatically deleted by Ubuntu, ensuring your long-term scripting projects remain perfectly safe.