Log Analysis with journalctl
Intermediate10 min
Search, filter, and analyze systemd journal logs to diagnose service failures, boot issues, and system errors.
Prerequisites
- -Linux with systemd
Steps
1
View logs for a specific service
Show all logs from a specific systemd service.
$ journalctl -u nginx --no-pager -n 50
2
Follow logs in real time
Stream new log entries as they are written.
$ journalctl -u nginx -f
3
Filter logs by time range
View logs from a specific time period.
$ journalctl --since '1 hour ago' --until 'now' --priority=err
Priority levels: emerg, alert, crit, err, warning, notice, info, debug. Use --priority=err to see only errors and above.
4
View boot logs
Show logs from the current or a previous boot.
$ journalctl -b -1 --priority=warning
-b 0 is the current boot, -b -1 is the previous boot. Use --list-boots to see available boot IDs.
5
Check journal disk usage
See how much disk space the journal logs are consuming.
$ journalctl --disk-usage
Use 'sudo journalctl --vacuum-size=500M' to reduce journal size to 500MB.
Full Script
FAQ
Discussion
Loading comments...