Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Systemd and Logging (Read-Only)

journalctl filters

Narrow the systemd journal with journalctl: filter by unit, priority, boot, time range, process and fields, combine filters and output formats such as json.

The systemd journal can hold millions of entries, so journalctl is mostly a filtering tool. Every option below narrows the stream; filters of different kinds are combined with AND, so -u nginx -p err --since today means "nginx, at error level or worse, since midnight".

Read the output with the same habits as any log: filter first, then page, then search. This page lists the filters you will use constantly and how they combine. The sandbox has no journal, so the real commands are read-only; the examples run the same ideas against a sample log with awk and grep.

Terminal
journalctl -u nginx -p warning --since "1 hour ago"
journalctl -b -1 -p err
journalctl _SYSTEMD_UNIT=sshd.service -o json-pretty -n 1

Try it

Bash Filtering a sample journal by priority and unit

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 Counting and last lines like -n and -g (simulated)

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

Terminal
journalctl [OPTIONS] [MATCHES]
Name Description
-u UNIT Only messages from that unit; repeat the option for several units (OR).
-p LEVEL Priority filter: a name or number (0 emerg to 7 debug). -p err means 3 and more severe; -p warning..err is a range.
-b [N] Messages from a boot: -b is the current one, -b -1 the previous. --list-boots shows them.
--since, --until Time window: "2026-03-01 09:00", yesterday, today, "2 hours ago", -30min.
-n N, -r Show the last N entries; -r prints newest first.
-f Follow new entries as they arrive, like tail -f.
-k Kernel messages only (the same source as dmesg).
-g PATTERN Keep entries whose message matches a regular expression.
-o FORMAT Output: short, short-iso, verbose, json, json-pretty, cat (message only).
FIELD=value Match a journal field exactly, such as _PID=812, _UID=1000, _COMM=sshd, SYSLOG_IDENTIFIER=myapp.
--no-pager, -x, -e Do not page; add explanatory help texts; jump to the end of the pager.
--disk-usage, --vacuum-time=2weeks Show how much space the journal uses, or delete old entries (root).

Returns: 0 on success. With -g or filters that match nothing it prints -- No entries -- and still exits 0 (newer versions may exit 1 for -g with no match).

Usage notes

  • Different filters AND, repeated matches of the same field OR. _COMM=sshd _COMM=cron shows both programs; adding -p err then restricts both.
  • Permissions. Normal users see only their own entries unless they are in the systemd-journal, adm or wheel group; use sudo otherwise.
  • The journal may be volatile. Unless /var/log/journal/ exists (or Storage=persistent is set), logs live in /run and vanish at reboot, which is why -b -1 may say "no entries".
  • Time zones. Times print in the local zone; add --utc to compare machines. Timestamps without a zone in --since are local time.
  • Machine-readable output. -o json gives one JSON object per line, ideal for jq; -o cat strips everything but the message for easy grep.
  • Find which fields exist with -o verbose -n 1, then filter on any of them.
  • -p err includes worse levels. It is a threshold, not an exact match. See Log priorities.
  • Do not pipe the live journal to grep for what -g or -u can do; the built-in filters use the journal's indexes and are far faster.