How To Use Journalctl to View and Manipulate Systemd Logs
Last Updated :
26 Feb, 2024
Journalctl is a powerful command-line utility in Linux for querying and displaying logs managed by systemd-journald. It lets users access detailed information about system events, services, and processes. With journalctl, you can filter logs based on various criteria such as time range, specific units, or log levels, enabling effective troubleshooting and analysis of system activity. This tool is integral for system administrators and users seeking comprehensive insights into the operational history of a Linux system.
What is Journalctl?
Journalctl is a command-line utility in Linux systems that allows users to query and display messages from the journal, a centralized logging system used by systemd. Systemd is a system and service manager for Linux operating systems. The journal contains information about various system events, including system startup messages, hardware events, kernel messages, and messages from various services and applications. journalctl provides a convenient way to view, filter, and analyze these log messages.
Features of Journalctl:
- Centralized Logging:
journalctl is part of the systemd suite, which introduces a centralized logging system. System logs are collected and stored in binary format, making them efficient and easy to access. - Rich Metadata: The journal includes rich metadata for log entries, such as the timestamp, log source (unit/service), priority, and other relevant information. This metadata enhances the ability to filter and search for specific entries.
- Flexible Querying: Users can query the journal based on various criteria, including time range, specific units (services), log priority, user ID, and more. This makes it easy to narrow down the scope of log entries for analysis.
- Human-Readable Output:
journalctl provides human-readable output, making it easier for users to interpret and understand log entries. The command formats and structures the information in a way that is accessible to administrators and developers. - Live Monitoring: The
-f the option allows users to follow and monitor the journal in real-time. This is particularly useful for observing system changes and facilitating troubleshooting and debugging.
How To Use Journalctl to View and Manipulate Systemd Logs
1. Basic Log Checking with Journalctl
The journalctl command in Linux is used to view system logs. Running it without any options (journalctl) displays logs from all services and programs, providing a comprehensive but potentially overwhelming overview of system activity.
Command:
journalctl
Output:

2. Filters in Journalctl
Using filters with journalctl enhances the precision of system log information, aiding in monitoring and troubleshooting server issues. Common filters include viewing logs for a specific service with the "-u [service]" filter and filtering logs by date and time using options like "--since" and "--until," as demonstrated by the command:
Command:
journalctl --since yesterday
Output:

To filter logs by a specific date and time using journalctl, the command is structured as follows: journalctl --since "YYYY-MM-DD HH:MM:SS". This format allows users to narrow down log entries to a precise time range, aiding in focused log analysis for troubleshooting or monitoring purposes.
Command:
journalctl --since " Date and Time "
Output:

The journalctl command efficiently filters logs by a specified time range using the "--since" and "--until" options. The example command, `journalctl --since "2022-02-28 00:00:00" --until "2022-02-28 23:00:00," displays log messages generated exclusively between 00:00 and 23:00 on February 28, 2022.
Command:
journalctl --since "2022-02-28 00:00:00" --until "2022-02-28 23:00:00"
Output:

3. Filtering logs of specific units/daemons/services.
On Linux systems, distinct services and programs produce specific log messages. Using journalctl -u [service] enables filtering logs for a particular service, such as journalctl -u cronie.service, revealing all log messages and errors associated with the cronie service.
Command:
journalctl -u cronie.service
Output:

Filtering by the unit name using journalctl streamlines the diagnosis of issues within a specific service, eliminating the need to sift through extensive system logs. This proves valuable for the efficient management and troubleshooting of Linux servers.
4. Getting Kernel Logs
The journalctl -k command selectively retrieves log messages solely from the Linux kernel, isolating errors, issues, and events at the kernel level from other program logs. This focused approach helps monitor and troubleshoot the operating system's core components.
Command:
journalctl -k
Output:

The command journalctl -k -b -1 retrieves kernel logs specifically from the most recent system boot, utilizing the -b option. Alternatively, by specifying a negative number with -b (e.g., -b -1, -b -2), logs from previous system boots can be obtained for further analysis.
Command:
journalctl -k -b -1
Output:

5. Disk Usage
The journalctl --disk-usage command on Linux systems using systemd provides a summary of the current disk space occupied by the system and kernel logs managed by the systemd-journald service. This helps assess the storage impact of logged information.
Command:
journalctl --disk-usage
Output:

Conclusions
In conclusion, the journalctl command allows filtering Linux system logs to extract relevant information for monitoring and troubleshooting. Using options like -u, -b, and -k provides visibility into logs of specific services, boot sessions, and kernel activity. Filters by time, text search further pinpoint logs. This makes inspecting verbose log data easier. Managing log storage is also important to avoid filling filesystems. Overall, journalctl with the right filters helps simplify log analysis for system administration.
Similar Reads
How To Use Journalctl to View and Manipulate Systemd Logs
Journalctl is a powerful command-line utility in Linux for querying and displaying logs managed by systemd-journald. It lets users access detailed information about system events, services, and processes. With journalctl, you can filter logs based on various criteria such as time range, specific uni
4 min read
How to Read and Edit Systemd Logs using Journalctl in linux
In the realm of Linux system administration, managing logs is an indispensable task. System logs are crucial for understanding the health, performance, and troubleshooting of a system. Systemd, the init system widely adopted by modern Linux distributions, introduced a centralized logging system call
6 min read
How to mask a systemd unit in Linux?
Systemd is a system and service manager for Linux operating systems, providing a range of functionalities for managing system processes. In some cases, you may want to hide or disable a systemd unit to prevent it from starting automatically. This process is known as "masking" a systemd unit. In this
6 min read
How to Send a Message to Logged Users in Linux Terminal?
Linux is a solution to the data center. It is flexible, stable, secure, and reliable. There are many users logged into servers for development purposes, testing, and usage. There are various tools to send messages to other users, but they do not allow widespread sending or sending to specific users
6 min read
How to Create API to View Logs in Node.js ?
Log files are essential for monitoring and troubleshooting applications. They provide insight into the application’s behaviour and help identify issues. In a Node.js application, you might want to create an API that allows you to view these logs easily. This can be particularly useful for centralize
5 min read
How to Install and Use Sysdig from Linux Command Line?
Sysdig is a tool that provides administrators and developers with unparalleled insight into their systems' behavior. The team behind it hopes to enhance system-level monitoring and troubleshooting by providing a centralized, coherent, and granular view of the storage, transmission, network, and memo
2 min read
How To Automate Podman With Systemd Integration?
Podman is an innovative container management solution providing a secure and lightweight alternative to standard containers such as Docker. Libpod, a container lifecycle management library included in this repository, serves as the foundation for Podman. APIs for managing containers, pods, container
5 min read
How To View Request Logs ?
Stackdriver Logging is the default log service provided by the Google Cloud Platform. Logging in to the Google Cloud Platform (GCP) is like keeping a detailed journal of everything that happens and when it happens in your Google Cloud environment. It is important to be aware of what is going on with
4 min read
How To Use Python To Parse Server Log Files
Server log files are an invaluable source of information for system administrators and developers. They contain records of various events and activities that occur on a server, such as requests, errors, warnings, and more. Parsing these log files can provide insights into system performance, securit
4 min read
How to Manage System Services in Linux | systemctl Command
Linux operating systems are known for their robustness and versatility, and managing system services is a crucial aspect of maintaining a well-functioning system. With the advent of systemd, a system and service manager for Linux operating systems, the systemctl command has become an essential tool
8 min read
How To View Request Logs On Google Cloud Platform ?
Google Cloud Platform Logs Explorer is a tool that enables users to retrieve view and analyze log data helping them troubleshoot problems and monitor their resources effectively. Logs are records of event ed through Google Cloud Console and log entries can be read through the Logging API or Google C
4 min read
How to Start, Stop and Restart Services in Linux Using systemctl Command
System services play a crucial role in the functioning of a Linux system, handling various tasks and processes in the background. systemctl is a powerful command-line tool that allows users to manage these services effectively. In this article, we will explore the basics of using systemctl to start,
9 min read
How to View Kernel Messages in Linux | dmesg Command
The Linux kernel is considered one of the core components of the Linux operating system. It helps in establishing the communication between the hardware and managed system resources. To monitor and troubleshoot the kernel's interactions with the hardware and software components, the dmesg command co
8 min read
Sysdig - System Monitoring and Troubleshooting Tool For Linux
Sysdig is an open-source, cross-platform, system exploration/diagnosing and troubleshooting tool for Linux. Sysdig was written in Lua program language. Sysdig also has a simple, intuitive, powerful, and fully customizable curses UI (User Interface) called Csysdig. System state and activity from a ru
2 min read
How to Assert Log Messages with JUnit in Java?
In Java applications, logging is essential for monitoring application behavior, debugging issues, and tracking performance. Verifying log messages is important for ensuring correct entries during specific actions. In this article, we will demonstrate how to assert log messages in tests using JUnit.
6 min read
Monitor Linux Daemon, Filesystem, CPU, Network and Files Using Monit
Monit is a utility tool for monitoring & managing processes, files, directories, and filesystems on a Unix System. A superpower or a super ability to start a process if it's not running, restart a process if it isn't responding, and stop a process if it uses high resources, that's what Monit(or)
3 min read
How to Log Python Messages to Both stdout and Files
Python Loggers are essential tools for tracking and debugging applications, allowing developers to record messages of various severity levels. By configuring loggers to output messages to both stdout and log files, developers can ensure real-time monitoring and persistent storage of logs for later a
2 min read
How to Set the Logging Level with application.properties?
In Spring Boot, logging is crucial for monitoring, debugging, and troubleshooting Java applications. Spring Boot provides a convenient way to configure logging levels using properties files, particularly the application.properties file of the Spring application. This allows developers to control the
5 min read
How to Manage Logs in Linux?
Linux log files are records of system activities, It contains information about processes, errors, and events. Managing these files is crucial for troubleshooting issues, analyzing system performance, and ensuring system stability by identifying security threats. This article will review the command
4 min read