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
journalctlThe 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:
journalctlExample Output
Here’s an example of what the journalctl command might return:
-- Logs begin at Mon 2023-04-10 10:12:13 UTC, end at Tue 2023-04-11 12:34:56 UTC. --
Apr 10 10:12:13 myhostname systemd[1]: Starting Journal Service...
Apr 10 10:12:13 myhostname systemd[1]: Started Journal Service.
Apr 10 10:12:13 myhostname kernel: Initializing cgroup subsys cpuset
Apr 10 10:12:13 myhostname kernel: Initializing cgroup subsys cpu
Apr 10 10:12:13 myhostname kernel: Initializing cgroup subsys cpuacctKey Options
-b / --boot: Show logs from the current boot or a specific boot.
journalctl -bTo view logs from a previous boot, you can specify the boot ID or an offset:
journalctl -b -1-k / --dmesg: Show only kernel messages (similar to
dmesg).journalctl -k-u / --unit [unit]: Show logs from a specific systemd service or unit.
journalctl -u ssh.service-f / --follow: Follow new log entries in real-time (similar to
tail -f).journalctl -f-p / --priority [priority]: Show logs with a specific priority level or higher.
journalctl -p errValid priority levels are:
emerg,alert,crit,err,warning,notice,info, anddebug.-o / --output [output]: Specify the output format (e.g.,
short,json,cat, etc.).journalctl -o json-n / --lines [number]: Show the last specified number of lines.
journalctl -n 50--since / --until [time]: Show logs since or until a specific time.
journalctl --since "2023-05-01 10:00:00" --until "2023-05-01 12:00:00"-S / --since [time]: Show logs since a specific time.
journalctl -S "2023-05-01 10:00:00"--disk-usage: Show the disk usage of the journal logs.
journalctl --disk-usage
Practical Examples
View Logs from a Specific Boot:
journalctl -b -1This command shows logs from the previous boot.
Show Kernel Messages:
journalctl -kView Logs for a Specific Service:
journalctl -u apache2.serviceFollow Logs in Real-Time:
journalctl -fFilter Logs by Priority:
journalctl -p warningOutput Logs in JSON Format:
journalctl -o json-prettyView Logs Since a Specific Time:
journalctl --since "2024-05-30 10:00:00"Check Journal Disk Usage:
journalctl --disk-usage
Related Commands
systemctl: The command to control the systemd system and service manager. Useful for starting, stopping, and managing services.
systemctl status ssh.servicedmesg: Display kernel ring buffer messages.
dmesglogrotate: A utility to manage the automatic rotation and compression of log files.
sudo logrotate /etc/logrotate.conf
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