5

Differences between /tmp and /var/tmp

view full story
linux-howto

http://linuxers.org – 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. (General)