/tmp & /var/tmp - safe to remove?

I thought these were cleaned out during boot. But mine are growing, granted not exponentially every day, but still things are there from 1st install date.

My question is can I remove content from those two directories?

I understand there are tweaks that can be made in a sys config file to do it during boot, but so far they have gone over my balding old head.
I even tried finding out how in the SDB documents but didn’t find it(yet).

One option to make sure /tmp files are killed on shutdown/reboot is to set up /tmp using tmpfs. Set up an /etc/fstab entry

tmpfs   /tmp         tmpfs   rw,nodev,nosuid,size=2G          0  0

or the systemd way

ln -s  /usr/share/systemd/tmp.mount /etc/systemd/system/tmp.mount

It will take effect at next boot. You can remove the old disk /tmp as Neil describes well here…

Better do not remove them. As you saw, they are used. Those programs will probably break when they can not use them.

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

cp /usr/lib/tmpfiles.d/tmp.conf /etc/tmpfiles.d/tmp.conf

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

I find it instructive to have lsof list all open files on occasion, especially under /tmp and /home:

lsof -nP | grep tmp
lsof -nP | grep home

Usually on my system, it’s the web browser keeping hundreds of files opened in many subfolders, also the desktop environment (SeaMonkey and KDE/Plasma5 in my case).
It lets me gauge roughly whether maybe my SSDs are getting stressed a bit too much, if tmpfs-mounting might be in order, and how all-in-all-blazingly fast our Linux rigs have become. :open_mouth:

Did this^^^ /etc/tmpfiles.d/ was empty
Then I change the lines in copied file

I changed the lines in the /etc/tmpfiles.d/tmp.conf
However, the 'd’s in your lines were 'q’s in my file.See next code lines.

# Clear tmp directories separately, to make them easier to override
# SUSE policy: we don't clean those directories
q /tmp 1777 root root -
q /var/tmp 1777 root root -


man 5 tmpfiles.d

Yeah that is part of what went completely over my head.
But after all is said and done, /tmp was cleared of things oldr that 1 day.
But> /var/tmp was not cleared of anything! it has things going back to 11/10/2108(install date) most of which are named like this


(221 of them), and one of this


As the man page says, q is used for sub-volumes when using btrfs. When not. it is equal to d.
This q seems to be relative new. It is not in the 13.1 man page (which I happen to have on-line), but it is in 15.0. So somewhere in between …

Maybe the not working on /var/tmp has something to do with btrfs, I do not know. But all those old files can of course be removed manualy when they use a considarable amount of space.

Re-reading the thread, I see that I warned against removing /tmp and /var/tmp. That was not what you suggested, you asked if you could remove the contents of those without fear for problems. And you can. Specialy those (very) old ones, that will not be open anymore for amy process because the processes wil have stoppen long ago due to a shutdown. Only take care about programs that are created/used since last reboot…

I’ll note that I am using:

D /tmp 1777 root root 7d
q /var/tmp 1777 root root 14d

for those two lines.

“/tmp” only has files since the last boot. But my entry for “/var/tmp” doesn’t clean out everything. There are two older directories – presumably because they are still being accessed. It is clean enough for me.

As a side note.

Using D! instead of D makes sure that cleaning only will take place at boot. Which might be important when using 1d, using 7d might assure that no active files are deleted.

All this depends of course on how often a boot is done. When the system is “never” booted (meaning several days, maybe weeks between boots), cleaning on boot only may not be what you want. and thus the 7d and no ! is probably a good solution.

It is of course not for nothing that I point to the man page. Everybody should invent his own best solution depending on his computer’s way of life.:wink:

Nothing formatted with btrfs. Does openSuSe use it regardless of how partitions are formatted?

I am not sure what you mean with “it” here.

When you mean the q (which has a btrfs connection in it’s description), I can point you to the man page and my remark in post #, where I say “When not, it is eqaual tp d”. In other words, when you do not have btrfs, read q as if there stands d.

(BTW, I have the same in my 15.0, no btrfs, but q in /usr/lib/tmpfiles.d/tmp.conf).

Edit: I still can not explain why the cleaning works for /tmp, but not for /var/tmp.