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

28

4

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?

thebackhand

Posted 2010-07-26T22:42:01.727

Reputation:

Answers

17

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.

Kaleb Pederson

Posted 2010-07-26T22:42:01.727

Reputation: 489

So by default, files in /var/tmp are not deleted automatically and are only deleted when the user manually deletes them? – None – 2010-07-26T23:26:43.727

2I don't think that's a given as it says it's "deleted in a site-specific manner," implying that you don't have any guarantees other than it won't be deleted across a reboot. But, I think it's likely that most distributions won't delete the files in that directory but will rely on the application to clean them up. – Kaleb Pederson – 2010-07-26T23:44:48.287

15

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)

Mark Wagner

Posted 2010-07-26T22:42:01.727

Reputation: 311

3To be more specific, they delete files that have not been accessed, modified or had a status change in the last 30d. – Didier A. – 2015-09-30T02:17:28.623