ZetCode

Linux journalctl Command

last modified October 23, 2026

The journalctl command in Linux queries the systemd journal. On systemd-based distributions, the systemd-journald service collects log messages from the kernel, system services, and applications, including everything services write to standard output and standard error, and stores them in a structured, indexed binary format.

Each journal entry has a message and many fields, such as the priority, the process ID, or the systemd unit, which journalctl can filter efficiently. Regular users see only their own logs, unless they are members of the systemd-journal or adm group; otherwise use sudo. When the output goes to a terminal, it is shown in a pager; --no-pager prints it directly.

Test setup

To have predictable log messages, we create a small service that writes a few lines and then fails.

webapp.sh
#!/bin/bash

echo "webapp starting on port 8080"

for i in 1 2 3; do
    echo "handled request $i"
    sleep 1
done

echo "<4>cache is 90% full"
echo "<3>database connection failed"
exit 1

Lines written to standard output by a service end up in the journal. A prefix such as <4> or <3> sets the syslog priority of a line, here warning and error.

webapp.service
[Unit]
Description=Demo web application

[Service]
ExecStart=/usr/local/bin/webapp.sh

The unit is installed in /etc/systemd/system and started with systemctl start webapp. We also log two messages with the logger command, using the tag backup; the second has the error priority: logger -t backup -p user.err "backup of /srv failed: disk full".

Showing recent entries

Without arguments, journalctl shows all entries from the oldest to the newest. The -n option shows only the last lines.

journalctl -n 5

Each line contains the timestamp, the host name, the program with its PID, and the message. The -r option reverses the order, so the newest entries come first, and -e jumps to the end in the pager.

$ journalctl -n 5
Oct 23 11:53:17 box webapp.sh[79]: handled request 3
Oct 23 11:53:18 box webapp.sh[79]: cache is 90% full
Oct 23 11:53:18 box webapp.sh[79]: database connection failed
Oct 23 11:53:18 box systemd[1]: webapp.service: Main process exited, code=exited, status=1/FAILURE
Oct 23 11:53:18 box systemd[1]: webapp.service: Failed with result 'exit-code'.

Logs of a service

The -u option shows the entries of a systemd unit.

journalctl -u webapp

The output contains both the messages of the program and the messages systemd logged about the unit, such as its start and failure. This is the first place to look when a service does not work; systemctl status webapp shows the last few of these lines too. The option can be repeated to combine several units.

$ journalctl -u webapp
Oct 23 11:53:15 box systemd[1]: Started webapp.service - Demo web application.
Oct 23 11:53:15 box webapp.sh[79]: webapp starting on port 8080
Oct 23 11:53:15 box webapp.sh[79]: handled request 1
Oct 23 11:53:16 box webapp.sh[79]: handled request 2
Oct 23 11:53:17 box webapp.sh[79]: handled request 3
Oct 23 11:53:18 box webapp.sh[79]: cache is 90% full
Oct 23 11:53:18 box webapp.sh[79]: database connection failed
Oct 23 11:53:18 box systemd[1]: webapp.service: Main process exited, code=exited, status=1/FAILURE
Oct 23 11:53:18 box systemd[1]: webapp.service: Failed with result 'exit-code'.

Filtering by priority

The -p option shows messages with the given priority or a more important one.

journalctl -p err
journalctl -p warning -u webapp --no-pager

The priorities are emerg (0), alert (1), crit (2), err (3), warning (4), notice (5), info (6), and debug (7). The first command finds all errors in the journal; the second shows warnings and errors of one unit. A range such as -p warning..err is possible as well. In a terminal, errors are highlighted in red.

$ journalctl -p err
Oct 23 11:53:15 box backup[82]: backup of /srv failed: disk full
Oct 23 11:53:18 box webapp.sh[79]: database connection failed
$ journalctl -p warning -u webapp --no-pager
Oct 23 11:53:18 box webapp.sh[79]: cache is 90% full
Oct 23 11:53:18 box webapp.sh[79]: database connection failed
Oct 23 11:53:18 box systemd[1]: webapp.service: Failed with result 'exit-code'.

Filtering by identifier

The -t option selects messages by their syslog identifier, which is usually the program name or the tag given to logger.

journalctl -t backup

This is useful for scripts that log with logger and for programs that do not run as a separate systemd unit, for example cron jobs.

$ journalctl -t backup
Oct 23 11:53:15 box backup[81]: backup of /home completed, 512 MB
Oct 23 11:53:15 box backup[82]: backup of /srv failed: disk full

Filtering by time

The --since and --until options limit the time range, and -g filters messages by a regular expression.

journalctl --since "10 minutes ago" -p err
journalctl -u webapp --since today -g request

Times can be absolute, such as "2026-10-23 09:00", or relative, such as "1 hour ago", yesterday, or today. The -g (grep) option matches the message field case-insensitively when the pattern is all lowercase. Filters of different kinds are combined with a logical AND.

$ journalctl --since "10 minutes ago" -p err
Oct 23 11:53:15 box backup[82]: backup of /srv failed: disk full
Oct 23 11:53:18 box webapp.sh[79]: database connection failed
$ journalctl -u webapp --since today -g request
Oct 23 11:53:15 box webapp.sh[79]: handled request 1
Oct 23 11:53:16 box webapp.sh[79]: handled request 2
Oct 23 11:53:17 box webapp.sh[79]: handled request 3

Output formats

The -o option changes the output format.

journalctl -u webapp -o short-iso -n 2
journalctl -u webapp -o cat -n 3
journalctl -t backup -o json -n 1 | jq '{MESSAGE, PRIORITY, SYSLOG_IDENTIFIER, _PID, _UID}'

The short-iso format uses ISO 8601 timestamps, and cat prints only the messages. The json format exposes all fields of an entry; we select a few of them with jq. Fields starting with an underscore, such as _PID and _UID, are added by journald itself and cannot be faked by the logging program. The verbose format shows all fields in a readable form.

$ journalctl -u webapp -o short-iso -n 2
2026-10-23T11:53:18+0200 box systemd[1]: webapp.service: Main process exited, code=exited, status=1/FAILURE
2026-10-23T11:53:18+0200 box systemd[1]: webapp.service: Failed with result 'exit-code'.
$ journalctl -u webapp -o cat -n 3
database connection failed
webapp.service: Main process exited, code=exited, status=1/FAILURE
webapp.service: Failed with result 'exit-code'.
$ journalctl -t backup -o json -n 1 | jq '{MESSAGE, PRIORITY, SYSLOG_IDENTIFIER, _PID, _UID}'
{
  "MESSAGE": "backup of /srv failed: disk full",
  "PRIORITY": "3",
  "SYSLOG_IDENTIFIER": "backup",
  "_PID": "82",
  "_UID": "1000"
}

Filtering by fields

Any field can be used as a filter in the form FIELD=value. The -F option lists the values a field has in the journal.

journalctl -F _SYSTEMD_UNIT | sort
journalctl _SYSTEMD_UNIT=webapp.service PRIORITY=3

The first command lists the units that have logged messages. The second one shows the error messages written by our service. Matches for different fields must all be satisfied; several values for the same field are alternatives. Other useful fields include _PID, _UID, and _COMM.

$ journalctl -F _SYSTEMD_UNIT | sort
cron.service
init.scope
ssh.service
systemd-journald.service
systemd-logind.service
webapp.service
$ journalctl _SYSTEMD_UNIT=webapp.service PRIORITY=3
Oct 23 11:53:18 box webapp.sh[79]: database connection failed

Boots

The -b option limits the output to the current boot, and --list-boots lists the boots recorded in the journal.

journalctl -b -u nginx -o short
journalctl --list-boots

Our test machine has just been started, so there is only one boot. On a system with a persistent journal, journalctl -b -1 shows the previous boot, which helps to find out why a system crashed or rebooted. The -k option shows kernel messages, like dmesg.

$ journalctl -b -u nginx -o short
Oct 23 11:53:11 box systemd[1]: Starting nginx.service - A high performance web server and a reverse proxy server...
Oct 23 11:53:11 box systemd[1]: Started nginx.service - A high performance web server and a reverse proxy server.
$ journalctl --list-boots
IDX BOOT ID                          FIRST ENTRY                  LAST ENTRY
  0 b13881b8d8884414abfbbe02a8c63132 Fri 2026-10-23 11:53:11 CEST Fri 2026-10-23 11:53:18 CEST

Following the journal

The -f option keeps journalctl running and prints new entries as they arrive, like tail -f.

journalctl -f -u webapp -n 0

While journalctl was waiting, we started the service again from another terminal, and its messages appeared live. The -n 0 option skips the old entries that are normally shown first. Press Ctrl+C to stop following; in our example, timeout stopped it.

$ timeout 7 journalctl -f -u webapp -n 0
Oct 23 11:53:21 box systemd[1]: Started webapp.service - Demo web application.
Oct 23 11:53:21 box webapp.sh[120]: webapp starting on port 8080
Oct 23 11:53:21 box webapp.sh[120]: handled request 1
Oct 23 11:53:22 box webapp.sh[120]: handled request 2
Oct 23 11:53:23 box webapp.sh[120]: handled request 3
Oct 23 11:53:24 box webapp.sh[120]: cache is 90% full
Oct 23 11:53:24 box webapp.sh[120]: database connection failed
Oct 23 11:53:24 box systemd[1]: webapp.service: Main process exited, code=exited, status=1/FAILURE
Oct 23 11:53:24 box systemd[1]: webapp.service: Failed with result 'exit-code'.

Disk usage

The journal limits its size automatically, but the space can also be checked and freed manually.

journalctl --disk-usage
sudo journalctl --vacuum-time=2weeks

The --vacuum-time option deletes archived journal files older than the given time, and --vacuum-size shrinks them to a given size, such as 500M. Only archived files are removed, so nothing was freed on our fresh system. Permanent limits are set with SystemMaxUse in /etc/systemd/journald.conf.

$ journalctl --disk-usage
Archived and active journals take up 16.0M in the file system.
$ sudo journalctl --vacuum-time=2weeks
Vacuuming done, freed 0B of archived journals from /var/log/journal.
Vacuuming done, freed 0B of archived journals from /var/log/journal/a799110e38ff4b39a0c43af084d6ed01.
Vacuuming done, freed 0B of archived journals from /run/log/journal.

Best practices for journalctl

Source

journalctl(1) manual page

In this article, we have used the journalctl command to view system and service logs, filter them by unit, priority, identifier, time, boot, and fields, change the output format, follow new entries, and manage disk usage.

Author

I am Jan Bodnar, a programmer and technical writer. I have been writing programming tutorials at ZetCode since 2007 and have published eight e-books. See about the author.

List all Linux tutorials.