Home UbuntuJournalctl on Ubuntu 24.04: Filter Systemd Logs Fast

Journalctl on Ubuntu 24.04: Filter Systemd Logs Fast

by Knowledge Base Linux
Journalctl on Ubuntu 24.04 — Journalctl on Ubuntu 24.04: Filter Systemd Logs Fast

When a service crashes at 3 a.m. or a server reboots for no obvious reason, the answer is usually already on the disk — buried in hundreds of thousands of log lines. On modern Ubuntu, those lines live in the systemd journal, and journalctl ubuntu logs are the fastest way to find them. Instead of grepping scattered files in /var/log, one command can show you everything from kernel messages to a single service’s output, filtered by time, priority, or boot.

Journalctl ubuntu logs flowing from Linux services into a central journal database

This guide shows how to read journalctl ubuntu logs on Ubuntu 24.04 like a sysadmin: the essential queries, time and priority filters, how to follow logs live, and how to keep log storage under control. If you manage services with systemd, see also our guide to managing services with systemd on Ubuntu, and for long-term central storage, our rsyslog central logging guide.

Prerequisites – Journalctl on Ubuntu 24.04

  • A server or VM running Ubuntu 24.04 LTS with sudo access.
  • At least one systemd service to inspect (for example ssh, nginx, or cron).
  • Basic comfort with the terminal. No extra software is needed: journalctl ships with systemd.

Journalctl Ubuntu Logs Basics – Journalctl on Ubuntu 24.04

The journal collects messages from the kernel, systemd itself, and every service that writes to stdout, stderr, or syslog. By default, journalctl without arguments shows the whole journal, newest entries last, inside a pager. Press q to quit, or add --no-pager when you want output piped to another command.

journalctl --no-pager | head -n 50
journalctl -b --no-pager

The -b flag limits output to the current boot, which is the single most useful filter when you are debugging a fresh problem. Use -b -1 for the previous boot, and journalctl --list-boots to see every boot the journal still remembers.

journalctl --list-boots
journalctl -b -1 --no-pager | tail -n 100

If --list-boots shows only the current boot, your journal is stored in memory only. That is normal on a default install where persistent storage is not enabled, and we fix it later in the storage section.

Filtering Journalctl Ubuntu Logs by Service and Priority

Most debugging starts with one service. The -u flag (short for --unit) shows only that unit’s logs, including its start, stop, and crash messages from systemd itself:

sudo journalctl -u ssh.service --no-pager | tail -n 50
sudo journalctl -u nginx.service -u php8.3-fpm.service --no-pager

You can pass -u more than once to combine units. Next, filter by severity so warnings and errors are not drowned in routine notices. Priorities run from 0 (emergency) to 7 (debug); -p err shows errors and worse, while -p warning adds warnings:

journalctl -p err -b --no-pager
journalctl -p warning -u nginx.service --no-pager

For kernel messages only, use -k. For a text search across message content, use --grep (available on the systemd version shipped with Ubuntu 24.04):

journalctl -k --no-pager | tail -n 50
journalctl --grep="Out of memory" --no-pager
journalctl --grep="timeout" -u myapp.service --no-pager

Filtering Journalctl Ubuntu Logs by Time

Time filters turn a huge journal into a short, relevant window. The --since and --until options accept dates, times, and relative expressions such as yesterday, today, and 2 hours ago:

journalctl --since "2026-10-25 08:00" --until "2026-10-25 09:00" --no-pager
journalctl --since "1 hour ago" -u nginx.service --no-pager
journalctl --since yesterday --until today -p err --no-pager

Combine time with service and priority filters for the classic incident query: what did this one service do, at error level, in the hour before the outage? That combination alone resolves a large share of routine troubleshooting.

Following Logs Live and Reading Structured Fields

To watch logs as they arrive — the equivalent of tail -f for the journal — use -f. Start it in one terminal, reproduce the problem in another, and watch the cause appear:

journalctl -f -u myapp.service
journalctl -f -p err

Every journal entry also carries structured fields you can query directly, such as the unit, the executable path, and the process ID. Show all fields for a single entry with -o verbose, or get machine-readable output with -o json for scripting:

journalctl -u ssh.service -n 5 -o verbose --no-pager
journalctl -u nginx.service -o json --no-pager | head -n 20

Two more fields are worth knowing. _SYSTEMD_UNIT is the unit name, and MESSAGE_ID identifies well-known event types. Filtering by field uses the FIELD=value syntax, for example journalctl _SYSTEMD_UNIT=ssh.service.

Controlling Journal Storage and Retention

The journal can grow quickly on a busy server, so check its size first:

journalctl --disk-usage

To make logs survive reboots, enable persistent storage. Create the journal directory, set Storage=persistent in /etc/systemd/journald.conf, and restart the journal service:

sudo mkdir -p /var/log/journal
sudo sed -i 's/^#Storage=.*/Storage=persistent/' /etc/systemd/journald.conf
grep -E '^Storage=' /etc/systemd/journald.conf
sudo systemctl restart systemd-journald

Then cap the size so logs never fill the disk. --vacuum-size removes the oldest entries until the journal fits the limit, and --vacuum-time removes entries older than a period:

sudo journalctl --vacuum-size=500M
sudo journalctl --vacuum-time=14d
journalctl --disk-usage

For permanent limits, set SystemMaxUse=500M and MaxRetentionSec=14day in the [Journal] section of journald.conf and restart systemd-journald again. Vacuum commands are one-off cleanups; the configuration values are what keep the size bounded over time.

Troubleshooting Journalctl Problems

Only the current boot is available. Persistent storage is not enabled. Follow the storage section above, then confirm with journalctl --list-boots after a reboot.

You see “No entries” for a service. Check the exact unit name with systemctl list-units --type=service. A common mistake is querying nginx when the unit is nginx.service — both usually work, but a typoed name returns nothing instead of an error.

Permission denied on other users’ logs. Regular users only see their own journal entries. Use sudo, or add your account to the systemd-journal group and log back in: sudo usermod -aG systemd-journal $USER.

Logs stop after a certain date. The journal was probably vacuumed or rotated by a size cap. Check journalctl --disk-usage and the SystemMaxUse setting, and consider shipping logs to a central server if you need longer retention.

Conclusion

Mastering journalctl ubuntu logs means reaching for three filters first: boot (-b), unit (-u), and time (--since and --until), then narrowing by priority (-p) when the output is still too noisy. Add -f for live debugging, structured output for scripts, and a size cap so the journal never becomes a disk problem of its own. The official reference for every option is the journalctl manual page. With these queries in your toolkit, the next 3 a.m. incident starts with an answer instead of a search.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.