Skip to content

Linux Foundations / Manage a Linux host ยท Step 43 of 50

Lesson: General LoggingSwitch
โ† Linux Foundations

System administration

General Logging

Find the general-purpose system log and use standard tools to search it.

Besides specialised logs, most systems keep a catch-all record of everyday activity. It is a good place to start when you do not yet know what is wrong.

Which file

The name depends on the distribution:

  • Debian and Ubuntu: /var/log/syslog
  • Red Hat, Fedora and related: /var/log/messages

These files are written by a syslog daemon such as rsyslog. If it is not installed, the files may be absent, and you read the same kind of information with journalctl. Recent Debian releases, for example, work this way by default.

Anatomy of a line

Jan  5 10:12:25 web01 systemd[1]: Started nginx.service.

From left to right: timestamp, host name, program and process ID in brackets, then the message. Some systems write timestamps in ISO format, such as 2026-01-05T10:12:25.123456+00:00.

Reading and searching

These files can be large, so do not print them whole. Reading them usually requires sudo or a group such as adm.

$ sudo tail -n 20 /var/log/syslog
$ sudo tail -f /var/log/syslog
$ sudo less /var/log/syslog

tail -f keeps showing new lines; stop it with Ctrl+C. In less, press G to jump to the end and / to search.

Filter with grep. -i ignores case:

$ sudo grep -i "error" /var/log/syslog
Jan  5 09:58:01 web01 app[812]: Error: cannot connect to database

A word search is only a start. Not every problem says "error", and not every "error" matters.

Older logs

Logs are rotated, so you may see syslog.1 and syslog.2.gz. Search compressed files with zgrep, or read them with zless:

$ sudo zgrep -i error /var/log/syslog.2.gz

A method

  1. Note the time the problem happened.
  2. Look at the lines around that time.
  3. Find the first unusual message, since later ones are often side effects.
  4. Narrow down by program name.

With the journal, journalctl --since "10:00" --until "10:15" shows a time window.

Try it

Find which general log your system has, or confirm it uses only the journal. Follow it in one terminal, run logger test123 in another, and watch the line arrive. The streams and text lab is useful for practising grep.

Check your understanding

General Logging

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.