Filtering, Displaying, and Maintaining Logs using journalctl in Linux (original) (raw)

Last Updated : 17 Nov, 2025

The journalctl command in Linux is one of the most powerful tools for viewing, filtering, and managing system logs managed by systemd-journald.

Filtering Logs by Message Interest

You can use the -g or --grep option in journalct to filter logs by specific keywords or messages of interest. This helps focus only on relevant log entries instead of reading through large amounts of data.

1. Basic Filtering by Keyword

Displays logs containing a specific word or message.

**Command:

journalctl -g "error"

**Output:

error

2. Filtering by Keyword Within a Time Range

Filters log entries containing a specific keyword within a given time period.

**Command:

journalctl -g "error" --since "2024-06-01 08:00:00" --until "2024-06-01 10:00:00"

**Output:

journalctl

3. Filtering by Multiple Keywords

You can search for logs that contain more than one keyword.

**Command:

journalctl -g "error" -g "warning"

**Output:

abc

4. Filtering by Exact Match

You can filter logs for messages that match a phrase exactly using regular expressions.

**Command:

journalctl -g "^Service started$"

Modifying the Journal Display

The journalctl command provides various options to customize how logs are displayed making them more readable or machine-friendly for automation.

1. Default Output

Displays logs in the default detailed format.

**Command:

journalctl

**Output:

lala

2. Short Output Format

Displays logs in a compact format with essential details only.

**Command:

journalctl -o short

**Output:

efg

3. JSON Output Format

Displays logs in JSON format for programmatic parsing.

**Command:

journalctl -o json

**Output (truncated):

json

4. JSON Pretty Format

Shows logs in human-readable JSON format.

**Command:

journalctl -o json-pretty

**Output:

ctl

5. Verbose Output

Displays logs with maximum detail, including internal metadata.

**Command:

journalctl -o verbose

**Output:

verbose

Journal Maintenance

Maintaining the system journal helps manage disk space and performance. Over time, logs can grow large - so it’s important to control size, age, and persistence.

1. Limit the Size of Journal Logs

Restrict the total space used by journal logs.

**Command:

sudo journalctl --vacuum-size=1G

**Output:

1g

2. Limit the Age of Journal Logs

Delete logs older than a specific time.

**Command:

sudo journalctl --vacuum-time=2weeks

**Output:

2-weeks-

3. Enable Persistent Log Storage

By default, some systems keep logs only in memory (lost on reboot).

**Commands:

sudo mkdir -p /var/log/journal
sudo systemctl restart systemd-journald

4. Compress Old Logs

Reduce disk space by compressing old archived logs.

**Command:

sudo journalctl --vacuum-files=5

**Output:

vaccum

5. Check Disk Usage of Journal Logs

To see how much space your logs are using:

**Command:

journalctl --disk-usage

**Output:

disk