journalctl
Overview
The journalctl
command queries the systemd journal. It’s used to view and analyze system logs collected by the systemd journal.
Syntax
journalctl [options]
Common Options
Option | Description |
---|---|
-f |
Follow new entries |
-n N |
Show last N entries |
-r |
Show in reverse order |
-u UNIT |
Show unit logs |
-b |
Show current boot |
-k |
Show kernel messages |
-p PRIORITY |
Filter by priority |
--since |
Show since time |
--until |
Show until time |
--no-pager |
No pager output |
-x |
Add explanations |
-o FORMAT |
Output format |
Key Use Cases
- System troubleshooting
- Service monitoring
- Security auditing
- Boot analysis
- Error investigation
Examples with Explanations
Example 1: Recent Logs
journalctl -n 50
Show last 50 entries
Example 2: Service Logs
journalctl -u nginx
Show nginx service logs
Example 3: Boot Logs
journalctl -b
Show current boot logs
Understanding Output
Priority levels: 0. Emergency 1. Alert 2. Critical 3. Error 4. Warning 5. Notice 6. Info 7. Debug
Common Usage Patterns
Follow logs:
journalctl -f
Time range:
journalctl --since "1 hour ago"
Error messages:
journalctl -p err
Performance Analysis
- Log size
- Storage usage
- Query performance
- Rotation policy
- Compression ratio
Additional Resources
Best Practices
- Regular monitoring
- Storage management
- Priority filtering
- Backup important logs
- Security review
Troubleshooting
- Error analysis
- Boot problems
- Service failures
- System crashes
- Security incidents
Output Formats
- short
- short-iso
- short-precise
- short-monotonic
- verbose