journalctl: filtering logs by service and by time on Ubuntu 24.04

  1. Goal
  2. Preparation
  3. Steps
  4. Step 1: View one service's logs
  5. Step 2: Limit the lines and follow live
  6. Step 3: Filter by time
  7. Step 4: Filter by severity
  8. Step 5: Limit to one boot
  9. Step 6: Search by keyword and view kernel logs
  10. Step 7: Control disk usage
  11. Check
  12. Common mistakes
  13. Summary
  14. References

Goal

systemd gathers the logs of every service in one place called the journal, and journalctl is the tool for reading it.

After this article you can filter logs by service, by time and by severity, and you know how to keep the journal's size under control.

It continues from systemctl on Ubuntu 24.04: enabling, disabling and restarting services and checking their status: when systemctl status reports an error, journalctl tells you why.

Preparation

Steps

Steps

Step 1: View one service's logs

sudo journalctl -u systemd-resolved

The -u (--unit) flag filters by unit name. You can repeat the flag to see several services on the same timeline, for example -u hello -u systemd-resolved.

Step 2: Limit the lines and follow live

sudo journalctl -u hello -n 50
sudo journalctl -u hello -f

-n 50 shows only the last 50 lines. -f (--follow) keeps the screen open and prints new lines as they appear, like tail -f; press Ctrl+C to stop.

This is very useful: keep one window running -f, run systemctl restart hello in the other, and watch what happens.

To see the newest line at the top, add -r (--reverse).

Step 3: Filter by time

sudo journalctl -u hello --since "1 hour ago"
sudo journalctl -u hello --since "2026-11-01 08:00:00" --until "2026-11-01 09:00:00"
sudo journalctl --since yesterday --until today

--since (-S) and --until (-U) accept dates and times in the form YYYY-MM-DD HH:MM:SS or relative phrases such as "1 hour ago", yesterday, today.

Times are shown in the machine's time zone; add --utc if you want UTC.

Step 4: Filter by severity

sudo journalctl -u hello -p err
sudo journalctl -p warning -b

-p (--priority) filters by level: emerg, alert, crit, err, warning, notice, info, debug. When you name one level, the result includes that level and the more severe ones.

So -p err gives errors and worse, very handy for a quick scan.

Step 5: Limit to one boot

sudo journalctl -b
sudo journalctl -b -1
sudo journalctl --list-boots

-b is the current boot, -b -1 is the one just before it.

You can only see older boots when the journal is stored persistently on disk (the /var/log/journal directory exists); if the journal lives only in memory, it is lost on reboot. --list-boots shows which boots still have logs.

Step 6: Search by keyword and view kernel logs

sudo journalctl -u hello -g "timeout"
sudo journalctl -k

-g (--grep) filters by a pattern in the message text; -k (--dmesg) shows only the Linux kernel's log of the current boot, replacing the dmesg command.

Step 7: Control disk usage

journalctl --disk-usage
sudo journalctl --vacuum-time=2weeks
sudo journalctl --vacuum-size=500M

--disk-usage tells you how much space the logs take. The two --vacuum-* commands permanently delete old journal files (by age or by total size) and cannot be undone.

Run them only when you are sure you do not need to keep those logs for an investigation; if in doubt, back them up first.

To set a lasting limit instead of cleaning by hand, look at options such as SystemMaxUse= in the journald.conf configuration file.

Check

A quick self-test: restart hello, then view its logs for the last 5 minutes.

sudo systemctl restart hello
sudo journalctl -u hello --since "5 minutes ago" --no-pager

If you see lines recording the stop and the start ("Stopping", "Started"), you have read the service's logs correctly.

You can also combine -u, -p err and --since in one command to narrow things down as far as possible.

The journal is also useful for network diagnosis:

if you have just used the tools in Checking network connectivity on Ubuntu with ip,ss,ping and tracepath and still cannot tell why a domain name does not resolve,

try sudo journalctl -u systemd-resolved --since "10 minutes ago" to see what the name resolution service reports.

Common mistakes

Summary

journalctl -u picks the service, -n and -f pick how to read, --since/--until pick the time, -p picks the severity, -b picks the boot.

Combine these flags and you will find the cause of a problem much faster than by opening log files one by one, and remember to manage the journal's size so the disk does not fill up.

References

journalctl: filtering logs by service and by time on Ubuntu 24.04