On my desktop, immediately after boot/login, I am now getting a series of notifications that file space is getting limited. My system runs on a 250 GB SSD configuration. Examination of the file system reveals that there thousands of .tmp files or files in /tmp/ folders (e.g. /var/tmp/ contains more than 150 GB of data some of which date back to 2019)
Why are they there? Which could be deleted? How is best to delete them?
Best is to remove all files in /tmp (and also /var/tmp) on boot.
To begin with you could remove all those files of years ago. That will give you some space to breath again. Basically you can delete all file older then the last boot.
A caring programmer would see that during stopping a program, the temporary files are deleted. Do not litter!
So finding out what program does litter your /tmp, might help in e/g/ filing a bug report. When nobody complains, not much will be done to improve.
I do not know why your /tmp is not cleaned at boot. On my systems I have /tmp as a tmpfs, thus it will be cleaned at shutdown already. But it depends on the size of the memory if this is doable. I once had this (but I am not sure if it is still 100% true.):
================================
For cleaning /tmp and /var/tmp at boot:
When there is not already a file /etc/tmpfiles.d/tmp.conf create it as a copy
Then change the lines
# Clear tmp directories separately, to make them easier to override
# SUSE policy: we don't clean those directories
d /tmp 1777 root root -
d /var/tmp 1777 root root -
into
# Clear tmp directories separately, to make them easier to override
# My policy: empty /tmp en /var/tmp on boot.
D! /tmp 1777 root root 1d
D! /var/tmp 1777 root root 1d
See man 5 tmpfiles.d
================================
For making /tmp a tmpfs:
Add an entry into /etc/fstab
Before mounting this file system for the first time (either by command, or by reboot) you should clean the present /tmp directory as good as possible. Existing contents will still occupy disk space when you mount a file system over it.
The SUSE approach doesn’t really appeal to me, although it is perhaps apparent why. Everyone’s needs for that would depend on their usage environment. A configurable file deletion facility would be preferable. In my case, I would probably be happy with a 5 day cycle (or even less, because I run down my PC every day, never continuously logged on).
By the way, I could not find a file called tmp.conf on my system. In the meantime, I decided to take the sledgehammer and remove all files older than today. There must have more than 6000 files and folders taking up at least 150 GB going back to 2019. Nevertheless, I am thankful for the insights provided by you guys to help me on the way.!!
Just for the record, the majority of the temporary files seemed to originate from the following applications:
in /tmp/
Evolution
LibreOffice
in /var/tmp/
Zypp* (mainly, but not all, empty folders)
cnij* (presumably generated by my Canon printer/scanner)
tmpwatch is good for something like this - I’ve been using it for years. It’s a one-shot way of doing what others are suggesting using the tmp.conf method for.
You have to install it (at least, I did on TW), but then you just use it to delete anything that hasn’t been accessed in ‘x’ hours:
tmpwatch 120 /tmp
That would delete anything not accessed under /tmp in 5 days (5*24=120).