journalctl is a powerful command-line utility for querying and displaying messages from the journal managed by systemd. This cheat sheet provides essential commands to navigate and extract information from the system journal effectively.

Viewing Journal Entries:

CommandDescription
journalctlDisplay all journal entries.
journalctl -n [number]Show the last [number] entries.

Filtering by Time:

CommandDescription
journalctl --since "2022-01-01"Show entries since a specific date.
journalctl --until "2022-02-01"Show entries until a specific date.
journalctl --since "1 hour ago"Show entries from the last hour.

Filtering by Unit or Service:

CommandDescription
journalctl -u [unit]Show entries for a specific unit or service.
journalctl -u [unit] --since "today"Show entries for a unit since today.

Filtering by Priority:

CommandDescription
journalctl -p [priority]Show entries with a specific priority.
journalctl -p errShow entries with “err” priority.

Output Format and Details:

CommandDescription
journalctl -o verboseShow entries in verbose mode.
journalctl -o jsonDisplay entries in JSON format.
journalctl -o short-preciseShow entries in short and precise format.

Searching for Keywords:

CommandDescription
journalctl /keyword/Search for a specific keyword in entries.

Exporting Journal Entries:

CommandDescription
journalctl > output.txtExport journal entries to a text file.
journalctl -o json > output.jsonExport entries in JSON format to a file.

Real-Time Monitoring:

CommandDescription
journalctl -fMonitor journal entries in real-time.

Conclusion

This journalctl cheat sheet covers essential commands to efficiently navigate and extract information from the systemd journal. Whether you’re troubleshooting or monitoring system events, these commands will help you effectively analyze the journal entries.