journalctl
Overview
journalctl queries the systemd journal — structured logs from the kernel, services, and many applications. On journald systems it replaces a large share of traditional /var/log/syslog grepping while adding boot-aware filters and machine-readable output.
Syntax
journalctl [options] [matches...]Matches look like FIELD=value (e.g. _SYSTEMD_UNIT=nginx.service, _PID=1234, PRIORITY=3).
Common Options
| Option | Description |
|---|---|
-u UNIT |
Messages for unit (repeatable) |
-b / -b -1 / -b ID |
Current / previous / specific boot |
-f |
Follow (like tail -f) |
-e |
Jump to end in pager |
-n N |
Last N entries |
-p PRIORITY / -p from..to |
Priority filter (err, warning, 0–7) |
-S / -U / --since / --until |
Time window |
-o short-iso / json / json-pretty / cat |
Output format |
-k |
Kernel messages only |
-x |
Extra explanations when available |
-g REGEX |
Message regex filter (newer) |
--disk-usage |
On-disk journal size |
--vacuum-size= / --vacuum-time= / --vacuum-files= |
Reclaim space |
--no-pager |
stdout for scripts |
-r |
Reverse (newest first) |
Key Use Cases
- Debug a failed service
- Follow live logs while reproducing a bug
- Inspect the previous boot after a crash/reboot
- Export structured logs for
jq/ SIEM
Examples with Explanations
Unit logs
journalctl -u ssh.service -n 50 --no-pager
journalctl -u nginx --since "1 hour ago"
journalctl -u nginx -u php8.3-fpm --since todayFollow
journalctl -u myapp -fPrevious boot / crash triage
journalctl --list-boots
journalctl -b -1 -p err..alert --no-pager
journalctl -b -1 -u kdump.serviceKernel / dmesg-like
journalctl -k -b
journalctl -k --since "10 min ago"Time window
journalctl --since "2026-08-10 09:00:00" --until "2026-08-10 10:00:00"
journalctl --since -30mPriority
journalctl -p err -b
journalctl -p warning..crit -u myappJSON for jq
journalctl -u nginx -o json -n 100 | jq -r '.MESSAGE'
journalctl -u nginx -o json-pretty -n 5Field matches
journalctl _COMM=sudo -n 20
journalctl _UID=1000 --since today | head
journalctl CODE_FILE=/usr/bin/something # when apps set structured fieldsDisk usage and vacuum
journalctl --disk-usage
sudo journalctl --vacuum-size=500M
sudo journalctl --vacuum-time=14dPersistent journals grow until vacuum or system policy limits apply.
Catalog / explain
journalctl -x -u NetworkManager -n 20Understanding Output
Default opens a pager. Each line includes timestamp, hostname, syslog identifier, PID, and message. Use --no-pager in scripts. Privileges: members of systemd-journal or adm (distro-dependent) can read more than their own user journals.
Notes & Pitfalls
- Without persistent storage (
/var/log/journal), logs may live only in volatile/run/log/journaland vanish on reboot.
- Vacuum carefully on hosts that need long forensic retention.
- Noisy units: rate-limit in the service or drop journal rate limits thoughtfully in
journald.conf.
grepon pager output is inferior to-u/-g/field matches for large journals.
Additional Resources
man journalctl
man journald.conf
man systemd.journal-fields