Page Content

Tutorials

Journalctl In Linux: Commands, Examples, and Cheat Sheet

Logs are referred to as the “black box” of the Linux operating system. The main tool for accessing and modifying these logs is journalctl.

What is journalctl in Linux?

A command-line tool called journalctl is used to query and view logs from journald, the systemd logging service.

Logs were kept in plain text files (such as /var/log/syslog) on previous Linux systems. This was altered by systemd-journald, which gathered information from the kernel, system services, and boot process and stored it in a binary, structured format. You can read that binary data using the journalctl interface.

What is journalctl in Linux?
What is journalctl in Linux?

What It Does and Why It’s Used

  • Centralization: It collects logs from all system services, the kernel, and the initial RAM disk in one location.
  • Speed: Compared to using grep on large text files, looking for a given timestamp in logs is much faster because they are indexed and binary.
  • Metadata: Each log entry contains metadata such as the particular service unit that generated it, the Process ID (PID), and the User ID (UID).
  • Persistence: It ensures that your disk doesn’t fill up with outdated data by automatically managing log rotation and storage restrictions.

Also read about What Is Linux Logging? How It Works, Log Files, And Features

journalctl Command in Linux with examples

1. Basic Viewing

To see every log entry (starting from the oldest), simply type:

Bash

journalctl

Note: Use the arrow keys to scroll and q to quit.

2. Real-time Monitoring (Tail)

To watch logs as they happen (similar to tail -f):

Bash

journalctl -f

3. Filtering by Time

This is where journalctl it shines. You can use natural language.

Bash

# Logs from today only
journalctl --since today

# Logs from a specific window
journalctl --since "2026-03-10 12:00:00" --until "2026-03-11 15:00:00"

# Logs from 10 minutes ago
journalctl --since "10 minutes ago"

4. Filtering by Service (Unit)

To see logs for a specific background service (like Nginx or SSH):

Bash

journalctl -u sshd

5. Kernel Logs

To troubleshoot hardware or driver issues:

Bash

journalctl -k

6. Checking Boot Logs

Linux keeps track of previous boots.

Bash

# List all previous boots
journalctl --list-boots

# See logs from the previous boot
journalctl -b -1

Also read about What Are The Different Types Of Linux Logs? Beginners Guide

Common Applications

  • Debugging Service Failures: journalctl -u service_name -xe offers the most current error messages and hints when a service fails to start.
  • Monitoring sshd Logs to identify unsuccessful login attempts are known as security auditing.
  • Performance monitoring involves looking for disk I/O faults or kernel “Out of Memory” (OOM) kills.
  • Finding the service that is slowing down the system startup process is known as boot troubleshooting.

Setting Up the Environment

Since journalctl is part of systemd, it is pre-installed on almost every modern Linux distribution (Ubuntu, Fedora, Debian, CentOS, Arch).

1. Verification

Check if the journal service is active:

Bash

systemctl status systemd-journald

2. Ensuring Persistent Logs

By default, some systems store logs in a “volatile” way (cleared on reboot). To make logs persist:

  1. Open the config file: sudo nano /etc/systemd/journald.conf
  2. Find the line Storage= and change it to Storage=persistent.
  3. Restart the service: sudo systemctl restart systemd-journald

3. Managing Disk Space

To prevent logs from taking up too much room, you can “vacuum” them:

Bash

# Keep only the last 500MB of logs
sudo journalctl --vacuum-size=500M

# Keep only the last 2 weeks of logs
sudo journalctl --vacuum-time=2weeks

journalctl Cheat Sheet (Linux Logs)

journalctl is a command used to view and manage logs collected by systemd in modern Linux distributions.

Basic Commands

CommandDescription
journalctlShow all logs
journalctl -bShow logs from current boot
journalctl -rShow logs in reverse order
journalctl -fFollow logs in real-time (like tail -f)
journalctl -n 50Show logs from the current boot

Example

bash

journalctl -n 20

View Logs by Time

Logs from the last hourDescription
journalctl --since todayLogs from today
journalctl --since yesterdayLogs from yesterday
journalctl --since "1 hour ago"Logs from last hour
journalctl --since "2026-03-10"Logs from specific date

Example

bash

journalctl --since "2 hours ago"

Also read about What Is A Linux Container? How Do Containers Work On Linux?

View Logs by Service

Example for SSH service

bash

journalctl -u ssh

Example for Docker

bash

journalctl -u docker

This shows logs for a specific system service.

View Logs by Priority

PriorityMeaning
0Emergency
1Alert
2Critical
3Error
4Warning
5Notice
6Info
7Debug

Example

bash

journalctl -p err

Shows only error logs.

View Logs by Boot

CommandDescription
journalctl --list-bootsShow boot history
journalctl -b -1Previous boot logs
journalctl -b -2Logs from two boots ago

Example

bash

journalctl -b -1

Filter Logs by Process

bash

journalctl _PID=1234

or

bash

journalctl _COMM=sshd

Disk Usage of Logs

bash

journalctl --disk-usage

Example output

bash

Archived and active journals take up 250M

Also read about How To Use Shell Command In Linux & Basic Shell Commands

Clean Old Logs

Remove logs older than 7 days

bash

sudo journalctl --vacuum-time=7d

Remove logs if size exceeds 500MB

bash

sudo journalctl --vacuum-size=500M

Output Formatting

CommandDescription
journalctl -o jsonOutput in JSON format
journalctl -o shortDefault short format
journalctl -o verboseDetailed output

Example

bash

journalctl -o json

Useful Combinations

Show logs for the SSH service in real-time

bash

journalctl -u ssh -f

Show errors from last boot

bash

journalctl -p err -b

Show the last 100 logs from Docker

bash

journalctl -u docker -n 100

Journalctl vs syslog vs dmesg

Featurejournalctlsyslogdmesg
PurposeView and query logs from the system journalTraditional system logging serviceDisplay kernel ring buffer messages
Logging SystemWorks with systemd-journaldUses syslog daemons like rsyslog or syslog-ngReads messages directly from the Linux kernel
Log Storage FormatBinary structured logsPlain text log filesKernel ring buffer (temporary memory)
Default Log Location/var/log/journal/ or /run/log/journal//var/log/syslog, /var/log/messages, /var/log/auth.logNot stored in files (temporary buffer)
Main Commandjournalctlcat /var/log/syslog or tail -f /var/log/syslogdmesg
Focus AreaSystem services, kernel, boot logs, applicationsGeneral system events and service logsHardware, drivers, and kernel messages
Filtering FeaturesAdvanced filters (time, service, boot, priority, PID)Limited filtering using tools like grepBasic filtering using grep
Boot Log AccessCan show logs from previous bootsUsually logs only current logs unless rotatedShows messages from current boot only
PerformanceFast searching (indexed logs)Slower search in large text filesFast (small kernel buffer)
Shows messages from the current boot onlyModern Linux log analysis and troubleshootingTraditional logging in older systemsHardware troubleshooting and kernel debugging

Also read about What Is Linux Kernel? Why It Is Important And Its Components

Hemavathi
Hemavathihttps://govindhtech.com/
Myself Hemavathi graduated in 2018, working as Content writer at Govindtech Solutions. Passionate at Tech News & latest technologies. Desire to improve skills in Tech writing.
Index