Member-only story
DevOps in Linux — /var

What is “/var” Directory
In Linux, /var
is a standard directory that stands for "variable files". As the name suggests, this directory contains data that changes frequently while the system is running.
The origins of the /var
directory in Unix and Linux systems can be traced back to the Unix Filesystem Hierarchy Standard (FHS). The FHS evolved from earlier attempts at filesystem standardization, beginning in the 1980s with the Filesystem Standard (FSSTND) for Linux. The goal was to define a standard filesystem hierarchy that would ensure software would correctly locate and use files, regardless of the specific Unix or Unix-like system.
The concept of the /var
directory was part of these standards from early on. Its role was to provide a location for files that change frequently while the system is running, such as logs, databases, and temporary files.
This directory is used to store data such as:
- System Logs: Logs are files that record system events on your computer, and they are usually stored in the
/var/log
directory. They are used for troubleshooting and analyzing the ways in which users are interacting with a system. - Spool files: These files are typically queued for processing of some kind. For example, emails and printer jobs are stored in the spool directory (usually
/var/spool
) until they are processed. - Cache from proxy servers: If your system runs a web server, the server’s cache might be located in a directory along the lines of
/var/cache
. - Databases: Many database servers store their data in the
/var/lib
directory. - Temporary files required by programs (optional): While many programs use
/tmp
or/dev/shm
, others use directories under/var
for temporary storage.
An example structure of /var
:
$ tree /var -L 1
/var
├── account
├── adm
├── cache
├── db
├── empty
├── games
├── gopher
├── kerberos
├── lib
├── local
├── lock -> ../run/lock
├── log
├── mail -> spool/mail
├── nis
├── opt
├── preserve
├── run -> ../run
├── spool
├── tmp
└── yp