31

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?

1

2 Answers 2

20

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.

2
  • So by default, files in /var/tmp are not deleted automatically and are only deleted when the user manually deletes them?
    – thebackhand
    Jul 26, 2010 at 23:26
  • 3
    I 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. Jul 26, 2010 at 23:44
16

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)

2
  • 5
    To be more specific, they delete files that have not been accessed, modified or had a status change in the last 30d.
    – Didier A.
    Sep 30, 2015 at 2:17
  • Well this is annoying. I had followed a guide online that told me to create a script and put it in /var/tmp. Now it's gone.
    – MrVimes
    Dec 15, 2021 at 10:36

You must log in to answer this question.