Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The /var/log Tour — A Guided Tour of the Classic Log Directories

/var/log is where the classic text logs live — the directories every admin eventually learns to open when something breaks, and the tour of what is actually in there.


What Is /var/log, and Why Tour It?

/var/log is the conventional home of system and application logs on Linux. Nothing is standardized about its contents — every program writes wherever its author decided — but the conventions are strong enough that almost every distro has the same landmarks: syslog or messages for general system events, auth.log or secure for logins, dpkg.log for package operations, and a pile of subdirectories for services. When a service misbehaves, the answer is in one of these files. Knowing which one is the skill this page is about.

Why Learn the Tour?

  • It is where the evidence is — install dates, login history, error messages, and reboot causes all end up here.
  • You do not have to guess — the layout is predictable enough that most logs can be found from memory.
  • It is the other half of journalctl — on systemd systems the journal holds structured logs, but plenty of software still writes plain files.
  • Disk-full mysteries live here — log growth is one of the most common causes of a full root filesystem.
  • Security questions are answered here — who logged in, when, and from where.

When Should You Use This Tour?

Read it once, then come back whenever a service fails, a disk fills up, or you need the history of a machine. It pairs with var-log tools: tail, less, and grep do most of the work, and journalctl covers the systemd side.


The Landmarks

The general system log

/var/log/syslog      Debian/Ubuntu
/var/log/messages    RHEL/Fedora/Arch

Everything and nothing: kernel messages, cron jobs, service startup, network events. The first place to look, and the first place to grep:

tail -50 /var/log/syslog
grep -i ssh /var/log/messages | tail -20

Logins and authentication

/var/log/auth.log      Debian/Ubuntu
/var/log/secure        RHEL/Fedora
/var/log/wtmp          binary log of logins (read with `last`)
/var/log/btmp          binary log of failed logins (read with `lastb`)
grep 'Failed password' /var/log/auth.log | tail
last | head            # successful logins
lastb | head           # failed attempts — needs sudo

wtmp and btmp are not text files; they are readable with last and lastb from the util-linux package.

Package management

/var/log/dpkg.log       Debian — every package operation
/var/log/yum.log        older RHEL/CentOS
/var/log/dnf.log        newer Fedora/RHEL
/var/log/pacman.log     Arch
grep ' install ' /var/log/dpkg.log | tail -20

This is how you find out what was installed, and when — a genuinely useful question to be able to answer.

Boot and shutdown

/var/log/boot.log
/var/log/wtmp          also records reboots

The kernel side

/var/log/kern.log      Debian kernel messages
dmesg                  live ring buffer (not a file)

On a systemd system, the same kernel messages are usually available through journalctl -k instead.


The Service Subdirectories

Most daemons write into their own directory or file:

/var/log/nginx/         access.log, error.log
/var/log/apache2/       Debian Apache
/var/log/httpd/         RHEL Apache
/var/log/mysql/         MySQL/MariaDB
/var/log/postgresql/    PostgreSQL
/var/log/cups/          printing

Check a service’s own directory before grepping the system log:

ls /var/log/nginx/
tail -f /var/log/nginx/error.log

When a web service fails, its own error log almost always names the cause — bind() to 0.0.0.0:80 failed (98: Address already in use) is the classic one.


Reading the Files

Follow a log live

tail -f /var/log/syslog
tail -F /var/log/syslog        # survives rotation and truncation

-F (capital) is the right flag for logs that get rotated; it reopens the file when the old one disappears.

Filter for what you care about

grep -i error /var/log/syslog | tail -30
grep 'Dec 05' /var/log/auth.log | grep 'session opened'
less /var/log/syslog
# inside less: /pattern to search, &pattern to filter to matches only

Count things

grep -c 'Failed password' /var/log/auth.log

Rotation — Why Logs Do Not Eat the Disk

Left alone, /var/log would fill every filesystem. The logrotate service compresses and rotates logs on a schedule:

/var/log/syslog        the current file
/var/log/syslog.1      yesterday, compressed
/var/log/syslog.2.gz   and older ones, gzipped
ls -lh /var/log/syslog*
zgrep 'Failed password' /var/log/syslog.2.gz    # search inside compressed logs

logrotate configuration lives in /etc/logrotate.conf and /etc/logrotate.d/. If a log is missing and you expected it, rotation is the first thing to suspect.

The *.gz files are not clutter — they are the compressed history, and zgrep reads them like any other file.


What the Journal Replaced

On systemd systems, journald writes structured logs to a binary store, and much of what used to be in these files now goes there instead. The practical consequences:

  • syslog and messages may still exist, but the journal is the more complete record.
  • journalctl -u nginx replaces grepping service files.
  • Plain-text files still exist for anything that logs to a file directly.

Use both: the journal for systemd services and time queries, the text files for everything else.


Common Pitfalls

Assuming the same file names on every distro. syslog vs messages, auth.log vs secure — if a path does not exist, list the directory before concluding the log is missing.

Reading only the current file. The event you want may be in yesterday’s rotated log. Use zgrep on the .gz files.

Forgetting permissions. Several logs are root-only. ls -l /var/log shows which; prefix with sudo when reading them.

Deleting logs to free space. Deleting a file that a running service still has open frees nothing until the service restarts — the space stays held. Rotate or truncate instead:

sudo truncate -s 0 /var/log/big.log    # frees the space, keeps the file

Trusting timestamps across timezones. Log times are local by default; across DST changes or timezone edits, the timeline can look broken when it is not.

Assuming logs prove intent. A log records what a program wrote, not what happened. Read them alongside dmesg and journalctl before drawing conclusions.


PageRelationship
journalctlThe structured journal; time-filtered queries the text files cannot do
dmesgKernel messages; kern.log is the file version of the same data
freeCheck memory when a service died mysteriously
vmstatLoad and paging behind a slow-service complaint
text-processing READMEgrep, awk, and sed — the tools for reading these files
archives READMEWhy rotated logs are .gz and how to read them with zgrep

The Tour Cheatsheet

PathContains
/var/log/syslog | messagesGeneral system events
/var/log/auth.log | secureLogins and authentication
/var/log/wtmpLogin history (last)
/var/log/btmpFailed logins (lastb)
/var/log/dpkg.log | dnf.log | pacman.logPackage operations
/var/log/nginx/, /var/log/apache2/Web servers
/var/log/kern.logKernel messages
/etc/logrotate.d/Rotation configuration
tail -F FILEFollow a log, surviving rotation
zgrep PATTERN FILE.gzSearch rotated logs

Learn the landmarks and /var/log stops being a mystery directory.