Linux, like nearly all operating systems, accumulates many temporary files. It may be helpful to know more about these files. Some users may want to know how to manage the temporary files to increase storage space. Thankfully, the temporary files and cache are stored under /var/, /tmp/, and ~/.cache/.
/var/ contains long-term temporary files that are kept between reboots.
/var/backups/ is Debian-specific and contains backups of various databases and files such as /etc/passwd, dpkg databases, /etc/gshadow, etc.
/var/cache/ stores application-specific cache. These files can typically be removed without causing issues or minimal issues.
/var/chroot/ contains the files associated with chroots. Untrusted and unstable applications can be run in a chroot in this directory.
/var/crash/ is where the crash-dumps are stored.
/var/games/ is a cache-directory specifically for games that are found under /usr/games/.
/var/lib/ contains important cache that stores information on a program’s current state and activity. Deleting or editing these files can be dangerous.
/var/local/ holds cache data for applications that are installed under /usr/local/ are kept here.
/var/lock/ provides a way for programs to publicly indicate that they are using a specific file or device (/dev/*). Other programs may check in this directory to be sure that a particular device of file is not currently being used by another program. This directory is frequently a soft-link (shortcut) to /run/lock/.
/var/log/ is the place that contains all of the system logs. The “logrotate” command typically manages the size of the logs and is initiated by the cron tables. Users with Root privileges can delete the logs without cause system damage. However, if something goes wrong with the system, then there will be no way of tracking the issue.
/var/mail/ stores the user mailboxes.
/var/metrics/ or /var/usermetrics/ contains various numerical data.
/var/named/ is the Berkeley Internet Name Domain (BIND) database
/var/opt/ contains the temporary files generated by programs installed under /opt/.
/var/run/ contains various temporary system info which changes after a reboot. For instance, a list of the active PIDs and system services is stored in here. Such data will be different the next time the system reboots.
/var/spool/ stores files related to queued tasks. For example, files the will be printed via a printer are stored here until they are processed. Deleting files in this directory should generally not be done.
/var/tmp/ is a lot like /tmp/. However, these files may be too large for /tmp/ or they are needed after a reboot.
/var/yp/ is the NIS (Network Information Services) database.
/tmp/ stores files that are deleted before shutting down or rebooting the system. /tmp/ is a mountpoint for the tmpfs virtual filesystem. This filesystem is on the RAM. Therefore, when the RAM is cleared or loses power, the temporary files are gone. Also, because this is stored on the RAM, large files will be placed under /var/tmp/ which is on the hard-drive. This helps to save RAM or store files that are larger than the free space in memory. Many of these files are being used by applications, so do not delete any of these files unless you know what you are doing. If this directory becomes too large/full, restart the system.
tmpfs provides a convenient way for programs and users to access this data easily as if they were files on a hard-drive. Permissions are set on these files that help prevent malicious code from ruining the system.
With Root privileges, the user could store files in here which is the same as placing the files directly on RAM. Remember, the files will be gone forever when the RAM is cleared whether that be due to power loss or a reboot.
Some applications may use a different directory instead of /tmp/. The “TMPDIR” environment variable specifies a path to a folder that can be used for temporary files. Users may set this variable. However, not all programs will use the value of this variable. Alternatives to “TMPDIR” include “TEMP” and “TMP”.
~/.cache/ contains long-term files that are specific to each user. These files can usually be deleted safely. ~/.cache/thumbnails is another directory for thumbnails. Many of the folders in here are named after the application that uses them.
Users can easily clear Linux’s temporary files by using various tools. BleachBit (http://bleachbit.sourceforge.net/) is an example of an open source tool that works on Linux and Windows. Bleachbit allows users to “preview” the files that will be deleted. This means that users can see a list of the files that will be deleted before they are removed. When run with Root privileges, the user can delete temporary system files. However, be careful when managing system files.
In a user’s home folder, the ~/.thumbs/ or ~/.thumbnails/ directory can be removed without problems. The directory contains thumbnails for files viewed in a file-manager (like Nautilus or Nemo). In a command-line, these thumbnails can be removed by typing “rm -rf ~/.thumbs/*” or “rm -rf ~/.thumbnails/*”.