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.
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.
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.
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
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(oradm) group, or usesudo. - Persistence: if
/var/log/journaldoes not exist, the journal lives in/runand is lost at reboot. Create the directory (or setStorage=persistentinjournald.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 jsongives one JSON object per line, ready forjq. Use-o catto see only message text. - Size control: limit it in
journald.conf(SystemMaxUse=500M) or clean manually withjournalctl --vacuum-size=200M. - In scripts: pass
--no-pageror 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
journalctlto read it (it is binary), but filtering by unit, boot or priority is far easier than parsing text.
Related
systemctl,dmesg,logger,logrotate- Lessons: Logging and journald, Disks and logs