This article hasn't been updated for over 5 years. The information below may be obsolete.

$TMPDIR environment variable

When the /tmp fills up on a system, this can be a real pain, and this issue can effect every user, and may result in destabilizing the system. Even after a system reboot the /tmp directory is still full. Manual intervention is required to free up space.

To avoid this we encourage our system users to use a temporary location other than /tmp within there $HOME directory for storing temporary files. This is achieved by setting the $TMPDIR variable in the ${HOME}/.profile or ${HOME}/.bashrc files. For example:

export TMPDIR=${HOME}/tmp

In my .profile I have the following code, which sets the variable and also creates the directory if it doesn't exist:

if [[ -d ${HOME}/tmp ]]; then
   TMPDIR=${HOME}/tmp
else
   mkdir ${HOME}/tmp 2>/dev/null
   TMPDIR=${HOME}/tmp
chmod 0700 ${TMPDIR} fi

On some of our operational systems we enforce this action, by placing the above snippet into both the /etc/profile and /etc/bashrc files.

On our Solaris™ systems /tmp is mounted as a tmpfs (Temporary File System) by default, meaning it resides in memory rather than on disk. This provides high-performance access for temporary files, which are automatically cleared upon reboot. This is not currently the default on Linux based systems, but I hope in the future it becomes the norm.