How long are files kept in /var/tmp/, and how to use the directory?

I'm always hesitant to use /var/tmp/, because I never quite know exactly how long the files are kept there for, or even what the directory is used for. What determines when a file gets removed from /var/tmp/, and how is the directory intended to be used?


Solution 1:

Per the Filesystem hierarchy standard (FHS), files in /var/tmp are to be preserved across reboots.

Per FHS-2.3:

The /var/tmp directory is made available for programs that require temporary files or directories that are preserved between system reboots. Therefore, data stored in /var/tmp is more persistent than data in /tmp.

Files and directories located in /var/tmp must not be deleted when the system is booted. Although data stored in /var/tmp is typically deleted in a site-specific manner, it is recommended that deletions occur at a less frequent interval than /tmp.

I'm not aware of any Linux distributions that automatically clean /var/tmp. IMO, the applications that use /var/www cleanup after themselves in some reasonable manner.

Solution 2:

All RHEL-based distros clean /var/tmp of files older than 30 days. I don't know about other distros. Look for a cron entry that invokes tmpwatch. On Fedora/RHEL it is /etc/cron.daily/tmpwatch. It has a line like:

/usr/sbin/tmpwatch "$flags" 30d /var/tmp

or

/usr/sbin/tmpwatch 720 /var/tmp

(720 hours = 30 days)