Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Packages and Services

Linux journalctl command

Reference for journalctl: read and follow the systemd journal, filter by unit, time, priority and boot, output formats, and manage journal disk usage.

journalctl reads the journal, the structured log database kept by systemd-journald. Everything services print to standard output or standard error, messages sent through syslog, and kernel messages end up there, each entry tagged with fields such as unit, process ID, priority and time. Instead of searching text files, you filter by those fields.

Without options, journalctl shows the whole journal, oldest first, in a pager. In daily use you almost always add a filter: a unit, a time range, a priority or the current boot.

Terminal
journalctl -u nginx --since "1 hour ago"
journalctl -b -p err
journalctl -f

Try it

The sandbox has no systemd journal, so these examples are read-only. They filter sample text shaped like journalctl output, using the same ideas (time range, unit, priority) with awk and grep.

Bash Filtering log lines like journalctl (sample data)

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 Priority levels and the shell check

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 [OPTION]... [FIELD=VALUE]... [FILE]
Option Description
-u UNIT Messages from a unit (repeat for several).
-b [N] This boot; -b -1 is the previous boot. --list-boots shows them.
-p LEVEL Priority: a name (err) or number (3). -p warning..err is a range.
--since, --until A time: "2025-01-10 09:00", yesterday, "1 hour ago".
-f Follow new entries, like tail -f.
-n N Show only the last N lines (default 10 when combined with -f).
-r Newest first.
-k Kernel messages only (like dmesg).
-o FORMAT short, short-iso, json, json-pretty, cat (message only), verbose.
-g PATTERN Show entries whose message matches a regular expression.
_PID=, _UID=, _COMM= Match on any journal field.
--no-pager, -x Print straight to the terminal; add explanatory help texts.
--disk-usage, --vacuum-size=SIZE, --vacuum-time=TIME Show journal size, or delete old entries.

Returns: 0 on success. When a filter matches nothing it prints "-- No entries --" and still returns 0, so test the output if a script needs to know.

Usage notes

  • Permissions: ordinary users see only their own entries unless they are in the systemd-journal (or adm) group, or use sudo.
  • Persistence: if /var/log/journal does not exist, the journal lives in /run and is lost at reboot. Create the directory (or set Storage=persistent in journald.conf) to keep logs between boots.
  • Combine filters: journalctl -u app -b -p warning --since "10 min ago" narrows quickly; a space between conditions means AND.
  • Machine-readable output: -o json gives one JSON object per line, ready for jq. Use -o cat to see only message text.
  • Size control: limit it in journald.conf (SystemMaxUse=500M) or clean manually with journalctl --vacuum-size=200M.
  • In scripts: pass --no-pager or the pager will wait for a key when stdout is a terminal.
  • Containers usually have no journal; services there log to standard output, which the container runtime collects.
  • Compared with log files: the journal needs journalctl to read it (it is binary), but filtering by unit, boot or priority is far easier than parsing text.