Home/Engineer/OS / Systems/journalctl: Filtering system…
OS / SystemsBeginnerUbuntuDebianCentOSRHELjournalctlsystemd

journalctl: Filtering systemd Logs by Service, Time, and Priority to Troubleshoot Failures

A practical guide to querying, filtering, and analyzing system logs with journalctl, covering real-world scenarios.

Contents
  1. Basic Queries
  2. Filtering by Service
  3. Time Range Filters
  4. Priority (Level) Filters
  5. Output Formats
  6. Practical Scenarios
  7. Managing Log Disk Usage

Basic Queries

Bash
# All logs (newest first)
journalctl -r

# Last 100 lines
journalctl -n 100

# Live stream (like tail -f)
journalctl -f

# Logs since boot
journalctl -b

# Previous boot logs (-1 = last boot)
journalctl -b -1

Filtering by Service

Bash
# Logs for a specific unit
journalctl -u nginx
journalctl -u nginx -f  # live

# Multiple units
journalctl -u nginx -u php-fpm

# Specific PID
journalctl _PID=1234

Time Range Filters

Bash
# Today's logs
journalctl --since today

# Specific time range
journalctl --since "2024-01-15 10:00:00" --until "2024-01-15 12:00:00"

# Since 1 hour ago
journalctl --since "1 hour ago"

Priority (Level) Filters

Bash
# error and above
journalctl -p err

# warning through error
journalctl -p warning..err

# Levels: 0=emerg, 1=alert, 2=crit, 3=err, 4=warning, 5=notice, 6=info, 7=debug

Output Formats

Bash
# JSON output (useful for log pipelines)
journalctl -u nginx -o json | jq '.MESSAGE'

# Messages only (cat format)
journalctl -o cat -u myapp

# Kernel messages only (dmesg alternative)
journalctl -k

Practical Scenarios

Bash
# Find the cause of a service crash
journalctl -u myapp -p err --since "1 hour ago"

# Cause of a boot failure
journalctl -b -1 -p err

# Check whether the OOM killer ran
journalctl -k | grep -i "oom\|killed process"

# Monitor failed SSH logins
journalctl -u sshd | grep "Failed password" | awk '{print $11}' | sort | uniq -c | sort -rn

# Save logs to a file
journalctl -u nginx --since today > /tmp/nginx-today.log

Managing Log Disk Usage

Bash
# Current journal disk usage
journalctl --disk-usage

# Delete old logs (older than 2 weeks)
journalctl --vacuum-time=2w

# Size limit (500MB)
journalctl --vacuum-size=500M

You can make these permanent by setting SystemMaxUse=500M and MaxRetentionSec=2week in /etc/systemd/journald.conf.

#journalctl#systemd
Editorial note

AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us

Topic-related official docs (auto-linked · not per-claim sources)Linux man pages ↗

Questions & answers

Ask a question about this guide. We'll review and reply.