The /var
directory in Linux is used to store files that are expected to change or grow in size during the normal operation of the system. The name “var” stands for “variable,” and it typically contains logs, spool files, caches, and other data that changes over time. Below are common subdirectories found within /var
and their purposes:
Common Subdirectories in /var
/var/log
- Stores system and application log files.
- Examples:
/var/log/syslog
or/var/log/messages
(general system logs)/var/log/auth.log
(authentication logs)/var/log/dpkg.log
(package management logs)
/var/tmp
- Contains temporary files that need to persist between reboots.
- Similar to
/tmp
but with less frequent cleanup.
/var/spool
- Contains data waiting to be processed.
- Examples:
/var/spool/mail
or/var/spool/postfix
(email queues)/var/spool/cron
(cron job data)
/var/cache
- Stores cached application data to improve performance.
- Examples:
- Package manager caches (e.g.,
/var/cache/apt
for Debian-based systems) - Application-specific cache files.
- Package manager caches (e.g.,
/var/lib
- Holds persistent state information for programs.
- Examples:
/var/lib/dpkg
(Debian package database)/var/lib/mysql
(MySQL database files)
/var/run
(or/run
in newer systems)- Contains runtime information such as PID files and socket files.
- Examples:
/var/run/sshd.pid
(PID file for the SSH daemon)/var/run/network
(network-related runtime data)
/var/lock
- Holds lock files to prevent multiple processes from accessing a resource simultaneously.
/var/www
- Stores web server files (e.g., for Apache or Nginx).
- This is often the root directory for hosted websites.
/var/crash
- Contains crash reports and core dumps.
/var/log/journal
(optional)- Used by
systemd
for persistent journal logs if configured.
- Used by
Key Characteristics of /var
:
- Files in
/var
are typically writable by system processes. - These files can grow in size; thus,
/var
is often placed on a separate partition to prevent it from filling up the root filesystem. - Administrators should monitor and manage disk space in
/var
regularly.