Skip to main content

Linux and servers · Beginner · 14 min

Search the systemd journal with journalctl

By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · systemd 259

You will find the log lines you need in the systemd journal by service, boot, time window, priority, text and field, turn them into JSON for jq, and read them without sudo.

On this page

When something breaks at 03:00, the answer is usually already in the journal. On Ubuntu, systemd-journald collects the output of every service, the kernel's messages and anything written to syslog, and stores it with structured fields: which unit wrote it, which process, which user, how serious it was. journalctl is how you query it.

Paging through journalctl with no arguments shows you everything since the journal began, which is rarely what you want. In this tutorial you will write a few practice entries, then cut the journal down with the filters an on-call admin reaches for: one service, one boot, a time window, a priority, a text pattern, a field. You will finish by turning entries into JSON for jq and reading the journal without sudo. Ubuntu 26.04 ships systemd 259.

Step 1 · Write some entries to search

Install jq, which you will use later to work with JSON output:

Bash
sudo apt update
sudo apt install -y jq

systemd-cat sends a command's output to the journal. -t sets the identifier the entries are filed under, and -p sets their priority. Write three lines under the identifier journal-demo:

Bash
systemd-cat -t journal-demo echo "demo: worker started"
systemd-cat -t journal-demo -p warning echo "demo: disk usage at 85%"
systemd-cat -t journal-demo -p err echo "demo: Payment queue unreachable"

A program can also set the priority itself by starting a line with a syslog level in angle brackets. <3> means error. Services get this for free, because systemd reads the prefix from their output:

Bash
echo "<3>demo: retry limit reached for invoice 4411" | systemd-cat -t journal-demo

Now make a real, short-lived service, so you have a unit to filter by. systemd-run starts a command as a transient unit, and --wait returns when it finishes:

Bash
sudo systemd-run --wait --unit=journal-demo-job sh -c 'echo "job: nightly export starting"; echo "<3>job: export failed, cannot reach db01" >&2'

systemd prints something like Running as unit: journal-demo-job.service followed by the run time. The unit disappears once it exits, but its log lines stay in the journal under its name.

Check it worked

Show the last five entries from your identifier:

Bash
sudo journalctl -t journal-demo -n 5 --no-pager

You see your four lines, each with a timestamp, the host name, journal-demo and a process ID, something like Nov 26 09:14:02 web01 journal-demo[2211]: demo: disk usage at 85%. In a terminal, the error lines are shown in red and the warning in yellow.

Step 2 · Narrow to one service

-u shows the entries of one unit. This is the first filter to try when a service misbehaves:

Bash
sudo journalctl -u journal-demo-job --no-pager

Both lines from the job appear, attributed to sh, the program the unit ran. The .service suffix is optional. Try it on a service every server has:

Bash
sudo journalctl -u ssh -n 20 --no-pager

Options you will combine with -u all the time:

  • -n 20 shows the last 20 entries. -n on its own means 10.
  • -e jumps to the end in the pager, so you start at the newest lines.
  • -r reverses the order, newest first.
  • --no-pager prints everything and returns to the prompt, which you want when piping to another command.

You can pass -u more than once to see two services interleaved in time order, for example sudo journalctl -u nginx -u php8.5-fpm --since -15min (use the unit names on your server). Interleaving often shows which one failed first.

-t journal-demo and -u journal-demo-job are different filters. -t matches the identifier a program chose for itself. -u matches the systemd unit the process ran in, which the program cannot fake. Prefer -u for services.

Check it worked

The -u journal-demo-job output shows job: nightly export starting followed by job: export failed, cannot reach db01, and nothing from journal-demo. You will also see systemd's own lines about the unit, such as Started journal-demo-job.service and journal-demo-job.service: Deactivated successfully. That is expected: -u also matches the messages systemd writes about the unit, not only the unit's own output.

Step 3 · Limit by time and by boot

Use --since (short form -S) and --until (-U) to set a time window. They accept relative times, words and full timestamps:

Bash
sudo journalctl -t journal-demo --since "10 minutes ago" --no-pager
sudo journalctl -t journal-demo --since -1h --no-pager
sudo journalctl -t journal-demo --since today --no-pager
sudo journalctl -t journal-demo --since "2026-11-26 09:00" --until "2026-11-26 09:30" --no-pager

Replace the date in the last line with the window you care about. When someone reports "the site was slow between 09:00 and 09:30", that is the query you run, with -u for the service in question.

Times you give to --since and --until are read in the server's time zone unless you add a zone. Check the server's zone with timedatectl. If your team works in West Africa Time (UTC+1) or East Africa Time (UTC+3) and the server does not, either convert the times people report before you search, or state the zone in the query:

Bash
sudo journalctl -t journal-demo --since "2026-11-26 09:00 UTC" --until "2026-11-26 09:30 UTC" --no-pager

--utc is a separate thing: it changes only how timestamps are printed, not how the --since and --until times are read. Use both together when you want the whole query and its output in UTC.

Every boot gets an ID. List the boots the journal knows about:

Bash
sudo journalctl --list-boots --no-pager

The newest boot has index 0, the one before it -1, and so on. -b limits output to one boot. On its own it means the current boot:

Bash
sudo journalctl -b -t journal-demo --no-pager

To find out why a server rebooted, or what happened just before it went down, read the end of the previous boot:

Bash
sudo journalctl -b -1 -e

Ubuntu creates /var/log/journal when systemd is installed, so the journal is kept across reboots and -b -1 works. If --list-boots shows only one boot after a reboot, the journal is in memory only. /tutorials/keep-the-systemd-journal-small-and-persistent shows how to fix that.

Check it worked

The --since today query shows the four practice lines you wrote (the 10 minutes ago one shows them too, if you wrote them in the last ten minutes). --list-boots prints a table with columns IDX, BOOT ID, FIRST ENTRY and LAST ENTRY, one row per boot.

Step 4 · Filter by priority

Every entry has a priority from 0 to 7, the same levels syslog uses:

| Number | Name | Typical use |
|---|---|---|
| 0 | emerg | The system is unusable |
| 1 | alert | Act immediately |
| 2 | crit | Critical failure |
| 3 | err | An error |
| 4 | warning | Something may go wrong |
| 5 | notice | Normal but significant |
| 6 | info | Routine messages |
| 7 | debug | Detail for developers |

-p err shows err and everything more serious. It is the quickest way to see what went wrong since the server started:

Bash
sudo journalctl -p err -b --no-pager

On a busy server, put a unit or time window with it. For your practice entries:

Bash
sudo journalctl -t journal-demo -p err --no-pager

A range in the form FROM..TO limits to a band of levels. This shows only errors and critical messages, leaving out the most serious alerts:

Bash
sudo journalctl -t journal-demo -p err..crit --no-pager

You can use the number instead of the name: -p 3 is the same as -p err.

Check it worked

-t journal-demo -p err shows two lines: Payment queue unreachable and retry limit reached for invoice 4411. The worker start-up line and the disk warning are left out. The second line got its priority from the <3> prefix, not from -p.

Step 5 · Search the message text

-g (or --grep) keeps only entries whose message matches a pattern. The pattern is a regular expression:

Bash
sudo journalctl -t journal-demo -g "queue|retry" --no-pager

Case follows a simple rule. An all-lowercase pattern matches in any case, so -g "payment" finds Payment queue unreachable. A pattern with a capital letter in it matches exactly:

Bash
sudo journalctl -t journal-demo -g "payment" --no-pager
sudo journalctl -t journal-demo -g "payment" --case-sensitive=no --no-pager

The two commands give the same result. Add --case-sensitive=yes to force exact matching for a lowercase pattern.

A security check you can run on any server is a search of the SSH log for failed logins:

Bash
sudo journalctl -u ssh --since today -g "Failed password|Invalid user" --no-pager

If nothing matches, journalctl prints -- No entries -- and exits with status 1. Keep that in mind in scripts: a search that finds nothing is not an error in your query.

-g searches only the message. To filter on who wrote it, use -u, -t or the field matches in the next step, then add -g on top.

Check it worked

The queue|retry search shows exactly two lines, the payment line and the invoice line. Both payment searches show demo: Payment queue unreachable.

Step 6 · Read kernel messages

-k (or --dmesg) shows only kernel messages. It implies -b, so you get the current boot. This is where you find disk errors, the out-of-memory killer and network card resets:

Bash
sudo journalctl -k --no-pager -n 30
sudo journalctl -k -p warning --no-pager

To check whether the out-of-memory killer ended a process before the last reboot, search the previous boot's kernel log:

Bash
sudo journalctl -k -b -1 -g "out of memory|oom-kill" --no-pager

Check it worked

The first command shows the kernel's start-up messages for this boot, with kernel: in place of a program name, such as lines about the CPU, memory and attached disks. The second command shows only the ones marked as warnings or worse. On a healthy server it may be short.

Step 7 · Match on journal fields

Each entry is a set of fields. See them all for the payment error with -o verbose:

Bash
sudo journalctl -t journal-demo -g "Payment" -o verbose --no-pager

Fields that begin with an underscore, such as _PID, _UID, _COMM (the command name) and _SYSTEMD_UNIT, are added by journald itself and a program cannot set them. That makes them good evidence when you investigate an incident.

To match a field, write FIELD=value as an argument:

Bash
sudo journalctl _TRANSPORT=stdout -n 5 --no-pager
sudo journalctl _UID=0 -p err --since today --no-pager
sudo journalctl _SYSTEMD_UNIT=ssh.service -n 5 --no-pager

_TRANSPORT=stdout picks entries a program wrote to its standard output, which is how systemd-cat and every service's output reach the journal. _PID works the same way. Take the process ID from any line, the number in square brackets, and run sudo journalctl _PID=2211, with your own number in place of 2211.

How several matches combine:

  • Different fields are joined with AND: _COMM=sshd _UID=0 means both.
  • The same field twice is OR: _COMM=sshd _COMM=sudo means either.
  • A + between groups is OR: _SYSTEMD_UNIT=ssh.service + _COMM=sudo.

When you do not know which values exist, -F lists every value a field has in the journal:

Bash
sudo journalctl -F SYSLOG_IDENTIFIER
sudo journalctl -F _SYSTEMD_UNIT
sudo journalctl -F PRIORITY

-F _SYSTEMD_UNIT is a quick way to find the exact name of a service you only half remember.

Check it worked

-o verbose prints the entry's fields one per line, including SYSLOG_IDENTIFIER=journal-demo, PRIORITY=3, _TRANSPORT=stdout, _UID=0 and _PID=. For a long-running service you also see _COMM, _EXE and _SYSTEMD_UNIT. journald reads those from /proc for the process that wrote the line, and a command as short as echo has often exited by then, so they can be missing from your practice entries. The <3> invoice line shows PRIORITY=3 too, taken from the prefix. -F SYSLOG_IDENTIFIER includes journal-demo in its list. -F PRIORITY prints the numbers in use, such as 3, 4 and 6.

Step 8 · Change the output and follow live

-o changes how each entry is printed. Three formats cover most needs:

Bash
sudo journalctl -t journal-demo -o cat --no-pager
sudo journalctl -t journal-demo -o short-iso --no-pager
  • -o cat prints only the message, for copying into a ticket.
  • -o short-iso uses timestamps like 2026-11-26T09:14:02+00:00, which sort and compare cleanly across time zones.
  • -o json prints one JSON object per entry, with most fields as strings. A field that holds binary or non-UTF-8 data is printed as an array of numbers, and a field that appears more than once in an entry is printed as an array.

JSON plus jq lets you reshape entries. This prints priority and message as tab-separated columns:

Bash
sudo journalctl -t journal-demo -o json --no-pager | jq -r '[.PRIORITY, .MESSAGE] | @tsv'

On call, a count of today's errors by program shows where to start:

Bash
sudo journalctl -p err --since today -o json --no-pager | jq -r '.SYSLOG_IDENTIFIER // "unknown"' | sort | uniq -c | sort -rn

--output-fields=MESSAGE,PRIORITY trims the JSON to the fields you name, plus a few the journal always includes, such as the cursor and timestamps. On a slow or prepaid mobile connection to the server, filter on the server and pipe to a file or -o cat instead of scrolling through the full journal in the pager. Less data crosses the link.

-f follows the journal like tail -f: it prints the last lines, then waits for new ones. Open it for your practice identifier:

Bash
sudo journalctl -t journal-demo -f

In a second SSH session, write one more line:

Bash
systemd-cat -t journal-demo echo "demo: live line"

It appears in the first session within a second. Press Ctrl+C there to stop following. -f works with every filter in this tutorial, so sudo journalctl -u nginx -p warning -f watches one service for trouble while you deploy.

Check it worked

The jq command prints lines like 3 demo: Payment queue unreachable, with the priority number first. The error count shows journal-demo and sh among the programs, each with its number of errors today.

Step 9 · Read the journal without sudo

As an ordinary user, journalctl shows only your own entries. It prints a hint that users in the systemd-journal group (and on Ubuntu, the adm group) can see all messages. Check which groups you are in:

Bash
id -nG

If adm or systemd-journal is in the list, you can already read the whole journal. The user created when Ubuntu is installed is usually in adm. Users you add yourself are not.

Membership of either group lets that user read every log on the server, including login attempts and other users' commands. Grant it only to people who would be trusted with sudo journalctl anyway.

To add yourself to the dedicated journal group:

Bash
sudo usermod -aG systemd-journal "$(id -un)"

$(id -un) is your own user name. Group changes apply to new logins, so log out of SSH and log back in.

To remove the access later, run sudo gpasswd -d "$(id -un)" systemd-journal and log in again.

Check it worked

After logging back in, id -nG includes systemd-journal, and this command runs without sudo and shows your practice entries:

Bash
journalctl -t journal-demo -n 3 --no-pager

There is no hint about other users' messages above the output.

Next steps

  • Make sure the previous boot is still there when you need it, and cap the journal's size, with /tutorials/keep-the-systemd-journal-small-and-persistent.
  • Put these queries to work on a failure, from first alert to cause, in /tutorials/find-the-cause-of-an-outage-in-server-logs.
  • Send your own app's output to the journal by running it as a unit, as in /tutorials/run-an-app-as-a-systemd-service.
  • Your practice entries age out with the rest of the journal under its normal retention. There is nothing else to remove.

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.