Tmp Directories

Lubuntu 24.04 Noble Numbat

Are any of the files in the /tmp and /var/tmp directories important enough to keep?
What cli command, preferably one-liner, would be used to remove the less important while retaining the more important?

Please have a look here: Using /tmp/ and /var/tmp/ Safely

My advice is leave them be, unless you absolutely know what your doing and why.

Note that /tmp/ and /var/tmp/ each define a common namespace shared by all local software.

Files and directories located in /var/tmp must not be deleted when the system is booted. Although data stored in /var/tmp is typically deleted in a site-speciļ¬c manner, it is recommended that deletions occur at a less frequent interval than /tmp.

Iā€™m not aware of any Linux distributions that automatically clean /var/tmp

1 Like

This question got me curious so I decided to investigate a little.

On Ubuntu 24.04, Lubuntu may be different, run this command:
sudo nano /usr/lib/tmpfiles.d/tmp.conf

There should be a line in the file with this (on my system at least):
D /var/tmp 1777 root root 30d

If my understanding is correct, the implication is that the system will clean temp files automatically after 30 days, creating the directory if needs be with the correct permissions.

But, as @1fallen correctly points out you should not be deleting files unless you know what the results will be.

Great Point thanks @rubi1200 , and some programs that depend on these will also clean them selfs at some point:
As rubi1200 shows:

# Clear tmp directories separately, to make them easier to override
q /tmp 1777 root root 10d
q /var/tmp 1777 root root 30d




BTW Welcome to Discourse @WyattWhiteEagle

1 Like
# Clear tmp directories separately, to make them easier to override
q /tmp 1777 root root 10d
q /var/tmp 1777 root root 30d

I just checked my 25.04 test install and this is what the file now shows.

If you run command ls -la from the various tmp folders in your system you will see that most of the files or folders are root owned so you should nt remove them.
Some may be owned by you as user so are probably safer to remove if you want to but generally, why bother? Most of those tmp files or folders are very small and cause no problems.

Mine showsā€¦
#Clear tmp directories separately, to make them easier to override
D /tmp 1777 root root 30d
#q /var/tmp 1777 root root 30d

I wonder if itā€™s safe to reconfigure those lineā€™s to thisā€¦
#Clear tmp directories separately, to make them easier to override
#D /tmp 1777 root root 30d
D /tmp 1777 root root 7d
#q /var/tmp 1777 root root 30d
q /var/tmp 1777 root root 7d

oh yeahā€¦and thank yall for all the welcomeā€™s

Why botherā€¦
In the past, Iā€™ve ran Stacer, Bleachbit, and a custom cleanup script.
Then after rebooting, I ran update && full-upgrade.
All the while my machine kept getting slower and slower at opening and running things.
It got up to 2 minutes just to open the terminal.

So, to put my mind at ease and have a happier *buntu, reconfiguring and cleaning everything safely possible after finding out what is causing the sluggishness and rectifying those.

Not sure about /var/tmp but since my system has MORE than enough memory resources, I just allocate /tmp to RAM. Everytime you reboot you start with a fresh, empty /tmp directory. See this topic for more information:
https://askubuntu.com/questions/173094/how-can-i-use-ram-storage-for-the-tmp-directory-and-how-to-set-a-maximum-amount

Thatā€™s a very old link and solution.

Have you tested it?

The author also gives clear warnings about possible consequences.

It still works. Iā€™m using it on two of my three machines. The third doesnā€™t have enough RAM so I left it on disk. Running 22.04.5LTS (havenā€™t upgraded on my two main machinesā€¦ still testing on the under-powered third). Both 22.04.5 systems have been running this way for two years with no issues whatsoever. My primary system has 64Gb of RAM, my laptop has 16Gb.

Fair enough. Thanks for responding.

1 Like