/var
data that changes as the system runs/var holds the files that keep changing. The name is short for variable. Logs grow, caches fill, mail and print jobs queue up — all of it here, so that the rest of the system can stay still while this part moves.
When something went wrong, the record of it is in /var/log.
Why it exists
Every directory at the top of the tree is there for a reason. This is the problem /var solves.
Logs can fill a disk. On its own partition, a full /var stops the logging but leaves the root filesystem with room to boot and be repaired.
Programs live in /usr and never write there. Anything they need to save while running goes to /var instead.
What you find inside
Not everything, but the entries worth recognising. Each is marked as a directory, a file, a link or a device.
- logdirectorySystem and service logs. The first place to look when something fails.
- libdirectoryState that services keep between restarts, including databases.
- cachedirectoryData that can be regenerated, such as downloaded packages.
- spooldirectoryJobs waiting to be handled: mail, printing, scheduled tasks.
- wwwdirectoryThe default web root on many distributions.
- tmpdirectoryTemporary files that are kept across a reboot.
At the terminal
Four commands that show what this directory is doing on a real machine.
sudo tail -f /var/log/syslogWatch the system log as new lines arrive. Fedora-family systems use /var/log/messages.
sudo du -sh /var/* | sort -hFind which part of /var is taking the space.
journalctl -u ssh --since todayRead one service’s log entries from systemd’s journal.
ls -lt /var/log | headList the logs most recently written to.
Handle with care
What goes wrong here, and what someone securing or attacking the machine looks at.
A full /var stops services that cannot write their logs or data. Log rotation normally prevents this; a runaway log is the usual cause when it does not.
auth.log records every login and sudo use. Attackers try to edit or delete it, which is why important servers send their logs to another machine as well.