Difference Between /var/tmp and /tmp

Are you confused between /var/tmp and /tmp? Do you want to know what is the difference between these two. We are sure you need to know this difference. This is one of the most common questions asked in Linux interview and the interviewer may ask you what is the difference between /var/tmp and /tmp?

There has been always discussion among the new Linux System Administrator that what is the difference between /var/tmp and /tmp and why they are used. So today in this tutorial we are going to solve your problem and will try to tell you about them.

 

difference between /var/tmp and /tmp

 

What is /var/tmp and /tmp?

 

As the name suggest and also many of you must already be knowing that /var/tmp and /tmp both are used for temporary storage within your linux systems.

You can put your data on /tmp and /var/tmp on a temporary basis and can continue your work. Both these filesystems are also used by program for temporary storage.

As a system administrator, you may be using this space for storing your packages (RPM’s) for patching, testing purposes, or anything you want to do temporarily.

 

Difference Between /var/tmp and /tmp?

 

The main difference between these two is in their retention period of the data. As per “pathname.com“, data stored in /var/tmp is more persistent than data in /tmp.

By default, data kept in /tmp live for 10 days and it’s 30 days for /var/tmp. This is the main difference between these two. Also, temporary content of program in /tmp is cleared after reboot.

 

On Red Hat Enterprise Linux 7, you can also use /tmp as a mount point for a temporary file storage system (tmpfs) and the files in /tmp are not stored on the hard drive except when memory is low, in which case swap space is used.

Thus, data of /tmp does not survive reboots.

 

Important files to be checked for /var/tmp and /tmp are as bellow.

RHEL 6: /etc/cron.daily/tmpwatch
RHEL 7: /usr/lib/tmpfiles.d/tmp.conf

 

On RHEL 7, if you will view “/usr/lib/tmpfiles.d/tmp.conf“, you will find below lines which clearly indicate the retention period of these two temporary filesystem.

 

# See tmpfiles.d(5) for details

# Clear tmp directories separately, to make them easier to override
d /tmp 1777 root root 10d
d /var/tmp 1777 root root 30d

 

d” means creating a directory if it does not exist yet with given permission and age.

The last option on line starting with “d” is the age of the directory. The age field only applies to lines starting with d, D, and x.

You can also stop automatic clean of /tmp or /var/tmp, just by removing “d” or set it to “-“.

 

On REHL 7, do check “man 5 tmpfiles.d

 


If you still have any questions or doubts, do not hesitate to comment below or email us. If you like the article do like and share it. If you want more such article do not forget to subscribe to our email newsletter (FREE).

Add Comment

wordpress hit counter