Available: permanent, freelance, remoteMorocco

ENFR
Contact me
Topics

NewsSystems

journalctl: find the right line in a few commands

Boot, period, service, severity, then keyword: filter the journal in the right order, and keep it across reboots.

El Mehdi Jouan

El Mehdi Jouan · Systems & support engineer

· 3 min read

On a server that has been running for weeks, the journal holds millions of lines. Scrolling through journalctl with no filter is pointless. What saves time is narrowing the search in the right order: which boot, which period, which service, which severity, and only then which word.

The commands below were run on Ubuntu 26.04 (systemd 259). I also ran every option in an AlmaLinux 8 container (systemd 239, the same base as RHEL 8 and Oracle Linux 8): all of them are accepted there.

Pick the boot

journalctl --list-boots --no-pager
journalctl -b
journalctl -b -1

-b alone gives the current boot. -b -1 gives the previous one, which is almost always what you want after an unexpected reboot: its last lines show what the machine was doing just before it went down.

journalctl -b -1 -n 100 --no-pager

If --list-boots shows a single boot on a machine that has already rebooted, the journal is probably not kept on disk (see below).

Pick the period

journalctl --since "2026-11-24 00:30:00" --until "2026-11-24 00:45:00"
journalctl --since "1 hour ago"
journalctl --since yesterday --until today

When a user says "it crashed around half past midnight", I take a quarter of an hour around it and read everything, with no other filter. A neighbouring service often holds the explanation.

Watch the time zone: dates are read in the machine's zone. If the server runs in UTC and the user speaks in local time, the window is off. timedatectl shows the current zone, and --utc forces UTC output.

Pick the service

journalctl -u nginx.service -b
journalctl -u nginx.service -u php-fpm.service --since today

You can repeat -u to read several units in one stream, sorted by time. It is useful to see the real order of events between a front end and its application.

For a program that is not a systemd unit, filter by identifier or by process name. The identifier depends on the version: with OpenSSH 10, connections are logged as sshd-session; on older versions it is sshd. -F (below) lists the values present:

journalctl -t sshd-session -n 20
journalctl _COMM=sshd-session -n 20

To find which values exist for a field:

journalctl -F _SYSTEMD_UNIT

Pick the severity

journalctl -p err -b
journalctl -p warning..err -b

-p err shows errors and everything more severe (crit, alert, emerg). The warning..err form gives a range. Levels follow syslog: 0 emerg, 1 alert, 2 crit, 3 err, 4 warning, 5 notice, 6 info, 7 debug.

For the kernel only (disks, memory, drivers):

journalctl -k -b -p err

Search for a word

journalctl -b -g 'fail|error' --case-sensitive=false

-g takes a regular expression. The option appeared in systemd 237 and only exists if systemd was built with PCRE2. On an older version, or if journalctl says it cannot match patterns, fall back to a plain pipe:

journalctl -b --no-pager | grep -iE 'fail|error'

Pick the format

journalctl -u nginx.service -o short-iso
journalctl -u nginx.service -o cat
journalctl -n 1 -o json --output-fields=MESSAGE,_PID
  • short-iso prints full dates with the time zone: it is the format I paste into a ticket.
  • cat keeps only the message: handy to compare two outputs.
  • json gives every field, so you can see the PID, unit or user behind a line.

-r reverses the order (newest first) and -f follows the journal live.

Keep the journal across reboots

The setting is Storage= in /etc/systemd/journald.conf. With auto, journald writes to disk only if the /var/log/journal directory exists. Otherwise it writes to memory in /run/log/journal, and everything is lost at reboot. In the AlmaLinux 8 image I examined, the setting is auto and the directory does not exist.

To check, then turn on persistence:

grep -E '^#?Storage' /etc/systemd/journald.conf
ls -d /var/log/journal
sudo mkdir -p /var/log/journal
sudo systemd-tmpfiles --create --prefix /var/log/journal
sudo systemctl restart systemd-journald

In the AlmaLinux 8 container, systemd-tmpfiles did give the directory the systemd-journal group and mode 2755. Restarting journald needs a running systemd: I did not run it during these tests.

A journal on disk takes space. To measure it:

journalctl --disk-usage

The limit is set with SystemMaxUse= in the same file. The --vacuum-size, --vacuum-time and --vacuum-files options delete archive files: these are permanent deletions, to run knowingly and never in the middle of an investigation.

The recipe I apply

journalctl --list-boots --no-pager
journalctl -b -1 -p warning --no-pager -o short-iso | tail -50
journalctl -u myapp.service --since "2026-11-24 00:30" --until "2026-11-24 00:45" -o short-iso

First the boot, then the severity, then the time window and the service. The keyword comes last. In that order, you reach the right line in a few commands instead of minutes of scrolling.

  • linux
  • journalctl
  • systemd
  • journald
  • rhel