deleting tmp files

This is probably a stupid question, but what are the cons of deleting all the tmp files. On other linux forums it is not recommended.
Pharses like this: “You shouldn’t do that, since there may be unix sockets in use (or needed) there.”. What files are safe to delete?
Sorry if this is in the wrong forum, it did not seem to fit any where.
Thank you

If you boot to runlevel 3 (command line interface), then deleting files in “/tmp” probably won’t cause serious problems.

If you boot to the graphic interface, then there are some sockets in “/tmp” that are important for graphic sessions.

You can copy “tmp.conf” from “/usr/lib/tmpfiles.d” to “/etc/tmpfiles.d” and then edit it. Use

man tmpfiles.d

for information on the file.

The idea is to configure it to clean out “/tmp” at boot.

As an addition to what @nrickert says, some text I gathered earlier:

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

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.

It ain’t a stupid question.

  • The /tmp/ and /var/tmp/ are world writeable system directories with the “T-Bit” set.
  • System and user processes can, and do, write temporary files in these directories.

Therefore, provided that, the system is “quiet”, a system administrator can remove everything in those “tmp” directories.

  • Catch-22 is the usage of the “tmp” directories by the system …

Systems such as openSUSE which use “systemd” can get around this by, dropping into the systemd “rescue” mode or, the “emergency” mode to allow this maintenance to be performed.

  • systemctl rescue
  • systemctl emergency

When dealing with the files located in the “tmp” directories, which are sockets, the preference is to use the “unlink” CLI command rather than “rm” …

You chose the correct forum.
[HR][/HR]Please be aware that, there are systemd services which periodically execute to clean-up (perform housekeeping on) the “tmp” directories plus, a couple of other clean-up tasks:

 > systemctl list-unit-files | grep -i 'clean'
initrd-cleanup.service                                           static
initrd-udevadm-cleanup-db.service                                static
system-update-cleanup.service                                    static
systemd-tmpfiles-clean.service                                   static
systemd-tmpfiles-clean.timer                                     static

And, the really good news, with Leap 15.1, SDDM is cleaning up the sockets it used to leave lying around in /tmp/ …

Thank you, to those you replied, much appreciated.