journalctl
journalctl
The journalctl
command in Linux is used to query and display logs from the systemd journal, which is the logging system provided by the systemd init system. It is a powerful and flexible tool for managing and viewing system logs, providing features like filtering, searching, and exporting logs.
Understanding journalctl
journalctl
The journalctl
command can access logs collected by the systemd journal service, which includes logs from the kernel, system services, and various other sources.
Basic Usage
To display all logs, simply run:
Example Output
Here’s an example of what the journalctl
command might return:
Key Options
-b / --boot: Show logs from the current boot or a specific boot.
To view logs from a previous boot, you can specify the boot ID or an offset:
-k / --dmesg: Show only kernel messages (similar to
dmesg
).-u / --unit [unit]: Show logs from a specific systemd service or unit.
-f / --follow: Follow new log entries in real-time (similar to
tail -f
).-p / --priority [priority]: Show logs with a specific priority level or higher.
Valid priority levels are:
emerg
,alert
,crit
,err
,warning
,notice
,info
, anddebug
.-o / --output [output]: Specify the output format (e.g.,
short
,json
,cat
, etc.).-n / --lines [number]: Show the last specified number of lines.
--since / --until [time]: Show logs since or until a specific time.
-S / --since [time]: Show logs since a specific time.
--disk-usage: Show the disk usage of the journal logs.
Practical Examples
View Logs from a Specific Boot:
This command shows logs from the previous boot.
Show Kernel Messages:
View Logs for a Specific Service:
Follow Logs in Real-Time:
Filter Logs by Priority:
Output Logs in JSON Format:
View Logs Since a Specific Time:
Check Journal Disk Usage:
Related Commands
systemctl: The command to control the systemd system and service manager. Useful for starting, stopping, and managing services.
dmesg: Display kernel ring buffer messages.
logrotate: A utility to manage the automatic rotation and compression of log files.
Conclusion
The journalctl
command is a comprehensive tool for managing and querying system logs in systems using systemd. Its powerful filtering and formatting options make it an indispensable tool for system administrators and users who need to troubleshoot and analyze system behavior.
help
Last updated