Short answer: by default, files that aren't accessed in three days are deleted from /tmp
Long answer:
This was changed significantly in MacOS Sonoma 14
Prior to Sonoma, it works like this:
launchd sets up /usr/sbin/periodic daily to run every 86400 seconds (1 day) (definition in /System/Library/LaunchDaemons/com.apple.periodic-daily.plist). Older versions of Mac OS scheduled it to run at 3:15 am each day.
/usr/sbin/periodic daily runs the scripts in /etc/periodic/daily, including 110.clean-tmps.
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.
- 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:".
In MacOS Sonoma, this was migrated to be controlled more directly with launchd
- There is a new launch daemon configured specifically for cleaning
/tmp in /System/Library/LaunchDaemons/com.apple.tmp_cleaner.plist
- Using
StartCalendarInterval, it runs /usr/libexec/tmp_cleaner daily at hour 0 (i.e. midnight)
tmp_cleaner is a shell script that is very similar to 110.clean-tmps used pre-Sonoma but it does not provide any easy way to override the 3 day setting. You'd have to manually edit this file (and do it again on OS update0
/var/folders/? – adib Sep 10 '18 at 23:12