Skip to content

journalctl — Systemd Journal Log Viewer

Overview

journalctl is used to query and view logs generated by systemd-journald. It collects logs from the kernel, systemd services, syslog, and stdout/stderr of managed processes into a structured binary journal.

Command type: External (systemd)
Location: /usr/bin/journalctl


Syntax

journalctl [OPTIONS] [MATCHES...]

Options & Flags Reference

Option Description
-u UNIT Filter logs by systemd unit name (e.g. -u nginx)
-f Follow logs in real-time (similar to tail -f)
-n N Show last N log entries (default: 10 when combined with -f)
-p PRIORITY Filter by log severity (emerg, alert, crit, err, warning, notice, info, debug)
-b Show logs from the current boot (-b -1 for previous boot)
--since TIME Show logs newer than specified time
--until TIME Show logs older than specified time
-o FORMAT Set output format (short, json, json-pretty, cat, verbose)
-k Show kernel logs only (equivalent to dmesg)
--vacuum-size=SIZE Reduce journal disk usage to specified size (e.g. 500M)
--vacuum-time=TIME Remove logs older than specified duration (e.g. 2weeks)

Examples

Service Log Filtering

# View all logs for Nginx service
journalctl -u nginx.service

# Follow live Nginx logs
journalctl -u nginx -f

# Show last 50 lines for Docker
journalctl -u docker -n 50

Time-Based Filtering

# Logs from today
journalctl --since today

# Logs from past 1 hour
journalctl --since "1 hour ago"

# Date and time range
journalctl --since "2026-07-28 09:00:00" --until "2026-07-28 11:00:00"

Severity Priority Filtering

# Show errors and higher severity across the whole system
journalctl -p err -b

# Show warnings and errors for Nginx
journalctl -u nginx -p warning..err

Exporting & Structured Output

# Export logs as formatted JSON (great for log aggregators / Datadog / Fluentd)
journalctl -u app.service -o json-pretty -n 5

# Show raw log message text only (no timestamps or hostnames)
journalctl -u app.service -o cat

Managing Journal Disk Usage

# Check current disk space occupied by journal logs
journalctl --disk-usage

# Clean up logs to keep maximum 1 GB
journalctl --vacuum-size=1G

# Clean up logs older than 7 days
journalctl --vacuum-time=7d

Interview Questions

How do you view logs from the previous boot using journalctl?

Use journalctl -b -1. To see a list of recorded boots, run journalctl --list-boots.

Why does journalctl use binary log files instead of plain text log files like /var/log/syslog?

Binary storage enables fast indexed searching by unit, time, PID, or field value without scanning raw text files. It also enforces log integrity, supports structured metadata fields (JSON), and reduces disk overhead.


Command Description
systemctl Inspect and manage systemd units
dmesg Print kernel ring buffer messages
tail -f Follow text files in real-time