System Logs
Something broke. The first place to look: logs. Linux logs everything, and knowing where to look is half the battle.
Log Locations
Traditional logs live in /var/log:
Key Log Files
| Log | Contains |
|---|---|
/var/log/syslog | General system messages |
/var/log/auth.log | Authentication (login attempts) |
/var/log/kern.log | Kernel messages |
/var/log/dmesg | Boot and hardware messages |
/var/log/apt/ | Package manager history |
Application Logs
Apps often have their own log directories:
/var/log/nginx//var/log/mysql//var/log/apache2/
Reading Logs
tail -f is Gold
When debugging a live issue:
tail -f /var/log/nginx/error.log
Then trigger the error in another window. You'll see it appear instantly.
journalctl - systemd Logs
Modern systems use journald instead of (or alongside) traditional logs:
Useful journalctl Options
| Command | Shows |
|---|---|
journalctl -u service | Logs for specific service |
journalctl -f | Follow (real-time) |
journalctl -b | Since last boot |
journalctl -p err | Errors only |
journalctl --since "1 hour ago" | Time filter |
journalctl -n 100 | Last 100 entries |
Common Troubleshooting
SSH Login Failures
Service Crashes
Kernel Issues
Boot Problems
Log Rotation
Logs rotate automatically to prevent disk filling:
Older logs are compressed (.gz). Read with zcat or zgrep:
You suspect nginx crashed in the last hour. What's the best command?
Quick Reference
| Command | Shows |
|---|---|
tail -f /var/log/file | Follow log in real-time |
journalctl -u service | Service logs |
journalctl -f | Follow all logs |
journalctl -p err | Error level only |
journalctl --since "1 hour ago" | Time-filtered logs |
dmesg | Kernel messages |
zgrep pattern file.gz | Search compressed logs |
Key Takeaways
- Traditional logs:
/var/log/ - Modern systems: use
journalctl tail -ffor real-time monitoringjournalctl -u servicefor service-specific logs- Filter by time with
--since - Old logs are compressed - use
zgrep
Congratulations! You've completed Chapter 8: System Information.
You now know how to check disk, memory, CPU, and logs - essential for any system administrator.
Next chapter: Networking Basics - understanding network commands.