Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Special Files and Directories

The /var/log directory

Reference for /var/log: syslog, auth.log, kern.log, dmesg, wtmp and journal files, log rotation with logrotate, permissions, and how to read and search logs.

/var/log is where Linux keeps its log files: records written by the kernel, system services and applications. When something breaks, this is the first place to look. Most files are plain text and can be read with cat, less, grep and tail.

Which files exist depends on the distribution and on whether systemd-journald or rsyslog is in charge. Debian and Ubuntu use syslog and auth.log; Red Hat family systems use messages and secure. Many systems keep binary journals under /var/log/journal that you read with journalctl instead.

Terminal
ls -l /var/log
sudo tail -f /var/log/syslog
sudo grep "Failed password" /var/log/auth.log

Try it

Bash Searching a log (sample file)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Rotation by hand (what logrotate does)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Common files (names vary by distribution):

Path Contents
syslog or messages General system messages.
auth.log or secure Logins, sudo, SSH, authentication failures.
kern.log, dmesg Kernel messages and boot-time hardware detection.
boot.log Services starting at boot.
dpkg.log, apt/, yum.log Package manager history.
wtmp, btmp, lastlog Binary login records: read with last, lastb, lastlog.
journal/ Binary journal files for journalctl.
nginx/, apache2/, mysql/ Per-application directories.

Permissions: many files are root:adm with mode 640, so you need sudo or membership in the adm group. Directories created by services are owned by that service's user.

Usage notes

  • Rotation: logrotate, run daily by a timer or cron, renames app.log to app.log.1, compresses older copies to .gz and deletes the oldest. Configuration lives in /etc/logrotate.conf and /etc/logrotate.d/. Read compressed rotations with zcat or zgrep.
  • Follow live: tail -f (or tail -F, which survives rotation) streams new lines. For journal-based systems use journalctl -f.
  • Time ranges: log lines begin with a timestamp, so grep '^Mar 1 10:' or awk ranges extract a window.
  • Deleting a log that is open does not free the disk until the service closes it. Truncate instead with : > file or truncate -s 0 file.
  • Disk full? Runaway logs are a classic cause: find them with sudo du -ah /var/log | sort -rh | head.
  • Security: logs may contain passwords typed at the wrong prompt, tokens and personal data. Keep permissions tight and ship important logs to a remote collector so an intruder cannot erase them.