Wednesday, 30 July 2025

Ubuntu when will temp directory be cleared

 In Ubuntu, files within the /tmp directory are generally handled in two primary ways regarding their removal:

  • On System Reboot:
    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 the TMPTIME variable in /etc/default/rcSA value of TMPTIME=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).
  • By systemd-tmpfiles-clean.timer:
    Modern Ubuntu systems often utilize systemd for managing temporary files. The systemd-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. 
Therefore, 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.

No comments:

Post a Comment