Skip to content

How Is Tmp Cleared

Tags: linux


That depends on your distribution. On some systems, it’s deleted only when booted; others have cron jobs deleting items older than n hours.

  • On Debian and derivatives
    • On Debian and in general, on boot rules are defined in
      • /etc/default/rcS.
  • On Ubuntu since version 15.10 and its derivatives: using tmpfiles.d.
    • The default tmp.conf only clears /tmp on boot.
    • For more details, see this answer.
  • On Ubuntu 15.04 and before: - using tmpreaper 2
    • which gets called by /etc/cron.daily,
    • configured via /etc/default/rcS and /etc/tmpreaper.conf. (Credits to this answer).
  • On distributions from Red Hat and its derivatives: by age
    • RHEL 7, 8 and others with SYSTEMD
      • configured via /usr/lib/tmpfiles.d/tmp.conf,
      • called by systemd-tmpfiles-clean.service.
    • RHEL 6
      • used /etc/cron.daily/tmpwatch.
  • On Gentoo:
    • used /etc/conf.d/bootmisc.

Example stock /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
q /tmp 1777 root root 10d
q /var/tmp 1777 root root 30d
# 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-*

Sources:
  • https://serverfault.com/questions/377348/when-does-tmp-get-cleared