Good practices in clearing temporary files in /var/tmp/

Hello,

I see the cron tasks run at scheduled time to clear temporary files. When I check files that are being cleared using the command systemd-tmpfiles --cat-confi I see the lines below:

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

I don’t think we are clearing any files in /var/tmp from this by default. Is this a good practice? Don’t we need to clear this directory at least in a month? Files in this directory are persistent across boot. So wouldn’t this create any issues?

cat /usr/lib/tmpfiles.d/tmp.conf

D /var/tmp 1777 root root 30d

Change your config file, 30d is 30 day, - is never clear

If you don’t need to clear it, don’t, you can create your own problems. This is especially true if you run a desktop that has many applications running.

Thank you @foxsquirrel

I am really confused if I should clear it or not. To make a decision, I might need to know the files inside /var/tmp are created by which application. How to identify this? Consider I am using debian IoT version. Which services might write these files?

That is the problem, if the directory is getting huge and your system is low on resources consider it. Also, consider how much you will gain by clearing it out. In the USA we say “If it ain’t broke, don’t fix it”. That holds with any system that is extremely complex.

1 Like

These files does not go away on boot. What if the memory is growing and over a period of time and consumed all resource? This might be a problem. So I am trying to understand how this /var/tmp/* files operates, what and what not to do. Because once I saw a list of files, more that 50 at least in that folder. Unfortunately I cleared those manually. So I have no clue what created those in first place.

I wish to try out anything that could work.

If you know what files you don’t need and can repoint temp file generator endpoints to /tmp those should evaporate upon reboot. You can drop a test file in and test and see if persists after reboot. Pretty sure bbb is configured like that.

As to Ubuntu OS, /tmp/ is cleaned up every time it is rebooted.

As to server, you have to decide how to clean it up.

Finally I found which service is creating more files on the /var/tmp directory. It is haveged.service

Now I can implement anything I wish to sort it out. Yet to look into that particular service settings. But now I know what is happenning. Thank you for your suggestions.

2 Likes