Temporary files galore

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.

1 Like

Why were they not removed during the Leap 15.x boot process? Is that a fault?

Without showing any relevant information… nobody knows…

You can also try to find out which programs fill your temp directory…

1 Like

ls -al /etc/tmpfiles.d/

1 Like
/> ls -al /etc/tmpfiles.d/
total 0
drwxr-xr-x 1 root root    0 Apr 28 17:08 .
drwxr-xr-x 1 root root 5956 Jun  8 08:55 ..

I suppose that if these temporary files are assumed to be useless after shutting down the system, why does it matter which process put them there?

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 -


# 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

man 5 tmpfiles.d


For making /tmp a tmpfs:
Add an entry into /etc/fstab

tmpfs             /tmp    tmpfs   size=25%,uid=root,gid=root,mode=1777 0 0


man 8 mount

specialy the section: Mount options for tmpfs.

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.

1 Like

You can copy the fs-tmp.conf and fs-var-conf from /usr/lib/tmpfiles.d to /etc/tmfiles.d, I have changed them to:

cat /etc/tmpfiles.d/fs-tmp.conf 
# Clear tmp directories
d /tmp 1777 root root 5d

That means cleaning after 5 days.

cat /etc/tmpfiles.d/fs-var-tmp.conf
d /var/tmp 1777 root root 5d

Also cleaning after 5 days.

man tmpfiles.d


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.!! :+1: :joy:

Just for the record, the majority of the temporary files seemed to originate from the following applications:
in /tmp/

in /var/tmp/
Zypp* (mainly, but not all, empty folders)
cnij* (presumably generated by my Canon printer/scanner)

As you may have seen, I have set it in my example to one day and @Sauerland has set it to five days.

And using a tmpfs sets it to: all deleted at every shutdown.

You read what I have written???

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).

1 Like

Sorry, I was busy musing the input from hcvv. But thanks for your input!