journalctl extras
Beyond the basics: persistent logs, previous boots, output formats, field filters, size limits, and writing your own log entries.
The basics (-u, -f, -p, --since) are on Searching logs. This page has the rest.
Logs from previous boots
| What | Command |
|---|---|
| List all boots in the journal | journalctl --list-boots |
| Previous boot | journalctl -b -1 |
| Two boots ago | journalctl -b -2 |
| The end of the previous boot (why did it crash or reboot?) | journalctl -b -1 -e |
| Who triggered a reboot? | journalctl -b -1 -g "reboot|shutdown|power" |
On Ubuntu the journal is persistent (kept in /var/log/journal/), so old boots are available. If --list-boots only shows one, create the folder: sudo mkdir -p /var/log/journal && sudo systemctl restart systemd-journald.
Filter by field
Every journal entry has fields. Filter on any of them:
| What | Command |
|---|---|
| By program | journalctl _COMM=sshd |
| By executable path | journalctl /usr/sbin/cron |
| By PID | journalctl _PID=1234 |
| By user | journalctl _UID=1000 |
By syslog tag (logger -t) | journalctl -t backup |
| Kernel only | journalctl -k (= _TRANSPORT=kernel) |
| Several values = OR | journalctl -u nginx -u php8.3-fpm |
| Show all values a field has | journalctl -F _SYSTEMD_UNIT |
| Explain messages (where available) | journalctl -xe |
Output formats
| Format | Command | Use |
|---|---|---|
| Short with full timestamps | journalctl -o short-iso | comparing with other logs |
| Microseconds | journalctl -o short-precise | timing problems |
| Message only | journalctl -o cat | grepping, counting |
| All fields of each entry | journalctl -o verbose | finding fields to filter on |
| JSON (one per line) | journalctl -o json | with jq |
| No pager, no truncated lines | journalctl --no-pager | scripts, copy-paste |
| UTC times | journalctl --utc |
# Units that logged errors today, counted
journalctl -p err --since today -o json | jq -r '._SYSTEMD_UNIT // "kernel"' | sort | uniq -c | sort -rn
Size and retention
| What | Command |
|---|---|
| How much space is used? | journalctl --disk-usage |
| Keep max. 500 MB now | sudo journalctl --vacuum-size=500M |
| Delete entries older than 30 days | sudo journalctl --vacuum-time=30d |
| Check the journal files | journalctl --verify |
Permanent limits in a drop-in file:
[Journal]
SystemMaxUse=1G # max. total size on disk
MaxRetentionSec=90day # delete older entries
sudo systemctl restart systemd-journald applies it.
Write your own entries
From scripts and cronjobs:
logger -t backup "Backup finished, 2.3 GB" # info
logger -t backup -p user.err "Backup FAILED" # as error
journalctl -t backup --since today # read them back
Services started by systemd don’t need this: everything they print goes to the journal automatically.
Send logs elsewhere
To collect logs centrally, rsyslog (installed) can forward everything to a syslog server:
*.* @@logs.example.com:514
@@ = TCP, @ = UDP. Then sudo systemctl restart rsyslog.