In macOS, how often is /tmp deleted?

How often is /tmp deleted? I thought it was cleaned out boot time and every three days if you don't reboot, but I can't find any authoritative source for this.

I'm running the latest 10.6. (I suppose I would be interested in changes in this behavior in previous OS versions.)


Solution 1:

Short answer: by default, files that aren't accessed in three days are deleted from /tmp

Long answer:

  1. launchd sets up /usr/sbin/periodic daily to run every day at 3:15 am (definition in /System/Library/LaunchDaemons/com.apple.periodic-daily.plist).
  2. /usr/sbin/periodic daily runs the scripts in /etc/periodic/daily, including 110.clean-tmps.
  3. 110.clean-tmps uses find to delete files not accessed (using the -atime and -mtime parameters to find) in $daily_clean_tmps_days days which aren't listed in $daily_clean_tmps_ignore.
  4. Those two variables (and other related variables) are defined in /etc/periodic.conf. (Since OS 10.7 there is a file /etc/defaults/periodic.conf which defines the defaults, but for overwriting these defaults you should still create /etc/periodic.conf – see the periodic.conf(5) manual page.) If you haven't modified this file, $daily_clean_tmps_days is set to 3.

periodic daily logs its output to /var/log/daily.out. Files deleted from /tmp are logged under the heading "Removing old temporary files:".