Proper way for cleaning /tmp /var/tmp at boot

I run some programs that populate /tmp and sometimes /var/tmp. These files are anywhere between 3-4GB. I will like to create /tmp and /var/tmp at boot with 777 permissions and a sticky-bit. I see a systemd linked configuration tmp.conf in /usr/lib/tmpfiles.d/ directory but it doesn’t recreate /tmp, /var/tmp. Can I replace ‘q’ with ‘d’ there?, and if I do that how I can set a sticky-bit before I log in plasmadesktop. I don’t know if the stick-bit exists by default or not. Earlier I wasn’t able to log in and I had to run chmod a=rawx,o+t on /tmp.

# cat /usr/lib/tmpfiles.d/tmp.conf 
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# See tmpfiles.d(5) for details

# 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 -

# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-%b-*
X /tmp/systemd-private-%b-*/tmp
x /var/tmp/systemd-private-%b-*
X /var/tmp/systemd-private-%b-*/tmp

# Remove top-level private temporary directories on each boot
R! /tmp/systemd-private-*
R! /var/tmp/systemd-private-*

I created a /etc/tmpfiles.d/tmp.conf earlier but it resulted into missing Xorg lock and I couldn’t log into plasmadesktop environment.

d /tmp 1777 root root -
d /var/tmp 1777 root root -

What is the correct strategy for clearing /tmp and /var/tmp?

I have fixed this issue, had a syntax error in /etc/tmpfiles.d/tmp.conf.

Just as a note – I have been using a “D” for “/tmp” in that file, to clean on boot.

However, with my newest installs, I am linking


lrwxrwxrwx 1 root root 28 Feb 14 11:39 tmp.mount -> /usr/share/systemd/tmp.mount

so that a “tmpfs” file system is mounted at “/tmp”.

That symbolic link is in “/etc/systemd/system”.

Nice, I will try that. Thank you.

FWIW, also described here
https://unix.stackexchange.com/questions/352042/systemd-backed-tmpfs-how-to-specify-tmp-size-manually