Differences between /tmp and /var/tmp

While reading an article today, I came across a pretty basic thing which I had never thought of before. Have you ever wondered what could possibly be the difference between /tmp and /var/tmp. Its not rocket science but there is still a fair chance that most of you linuxers might not be aware of this basic fact (just like me ).

As the name suggests, /tmp is to be used by the programs to save temporary data. They shouldn't expect the data to be preserved in the /tmp folder between the invocations of the program. According to the recommendation of the Filesystem Hierachy standard (FHS), the files and directories located in /tmp should be deleted whenever the system is booted.

Although the data stored in /tmp folder can be deleted in  a site-specific manner, most of the Linux based systems follow FHS standard now.

Since in most of the default installations the /tmp folder will be cleaned in every reboot. This is where /var/tmp comes in to play. Here, applications can expect their data to be preserved between reboots. In other words, data stored here is more persitant than /tmp.

How to set the deletion time interval of files in /tmp folder for Debian/ubuntu based systems?

You can always set the time interval for deletion by setting the variable TMPTIME in /etc/default/rcS. Open the file /etc/default/rcS and change the value of the variable TMPTIME to the number of days you want your data to survive /tmp. For example, a value 6 will ensure that only data older than 6 days will be deleted on reboot. A value of 0 means that clean the whole /tmp.

How to set the deletion time interval of files in /tmp folder in Fedora/RedHat based systems?

A important point to note is that not all data is deleted on boot here. You may want to check the scripts in /etc/cron.daily/tmpwatch and /etc/rc.d/rc.sysinit. In Fedora/RedHat based systems, you can't control the deletion time for /tmp data using a single variable, since it is controlled by cron you can configure it according to your needs.

Basically different Operating systems following the FHS model have different ways of handling deletion of data in /tmp folder. So, you might want to check out the respective OS documentation about how it handles it.

3 Comments

Meanasspenguin (not verified)
March 12th, 2010 07:42 am
This is a handy bit of knowledge. In fact, I've known several people that didn't even know about the existence of /var/tmp. I'd like to point out that it's important to remember that on systems which are publicly accessible (like web hosting servers), the /var/tmp should be equally as secured as /tmp. So, if some of the precautions you take (like loop mounting noexec to /tmp) - you might want to consider doing the same to /var/tmp.
lefty.crupps (not verified)
March 12th, 2010 06:55 pm
I've become very disappointed that /var/tmp/ holds some of my desktop settings; isn't this meant to be stored in my /home/ , as my account, without outside access if I choose?
Ridgeland (not verified)
March 12th, 2010 07:56 pm
I use Gnome. I checked /var/tmp and the only thing there is /var/tmp/kdecache-ridgeland Lot of layers under that for a greeting card program I looked at but dropped, stuck there forever I guess. I think it's a KDE issue, not a gnome issue.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.