In Ubuntu, files within the /tmp
directory are generally handled in two primary ways regarding their removal:
- The most common method of clearing
/tmp
is during a system reboot. By default, Ubuntu and other Debian-based distributions are configured to remove files from/tmp
when the system starts up, particularly if their modification time exceeds a certain threshold defined by theTMPTIME
variable in/etc/default/rcS
. A value ofTMPTIME=0
will cause files to be removed regardless of age on boot, while other values specify a grace period (e.g.,TMPTIME=7
for 7 days). - Modern Ubuntu systems often utilize
systemd
for managing temporary files. Thesystemd-tmpfiles-clean.timer
service is typically configured to run daily and clean up temporary files based on rules defined in/usr/lib/tmpfiles.d/tmp.conf
and potentially other configuration files in/etc/tmpfiles.d/
. These rules specify the age after which files in various temporary directories, including/tmp
and/var/tmp
, should be removed. For instance, files in/tmp
might be cleaned after 10 days of inactivity, and those in/var/tmp
after 30 days.
tmp
directory files are removed either upon system reboot or periodically by the systemd-tmpfiles-clean.timer
service, depending on their age and the system's configuration.