Logs & Journald

💤0
Lv 10 XP
← 🧱 Foundations · Linux Fundamentals

Logs & Journald

Intermediate ⭐ 80 XP ⏱ 16 min #linux#logs#journald#troubleshooting

Find and read system and application logs to diagnose what went wrong.

📖Theory

Logs are your first stop when something breaks. Traditionally they live as text files in /var/log (syslog, auth.log, dmesg, plus app-specific files). On systemd machines, the journal centralizes logs and you query it with journalctl — filterable by service, time, and priority.

The skill is filtering: a busy system produces millions of lines, so you narrow by unit (-u), time (--since), and severity (-p err) to find the signal.

🌍Real-World Example
journalctl -u nginx --since "1 hour ago"   # one service, recent
journalctl -p err -b                        # errors from this boot
journalctl -f                               # follow everything live
journalctl --since "2026-06-22 09:00"       # from a timestamp

tail -n 100 /var/log/syslog                  # last 100 lines
grep -i "failed" /var/log/auth.log           # failed logins
✍️Hands-On Exercise
  1. Show all error-priority messages from the current boot.
  2. Follow a service’s logs live while you restart it.
  3. Use grep to find failed SSH login attempts in /var/log/auth.log.
  4. Filter the journal to the last 10 minutes for a single service.
🧾Cheat Sheet
TaskCommand
Service logsjournalctl -u svc
Follow livejournalctl -f
Since timejournalctl --since "1 hour ago"
This boot onlyjournalctl -b
Errors onlyjournalctl -p err
Text log tailtail -f /var/log/syslog
Kernel ring bufferdmesg
💬Common Interview Questions
Where do logs live on a Linux system?

Traditional text logs are in /var/log (syslog, auth.log, etc.). On systemd systems the binary journal is queried with journalctl.

How do you filter the journal to one service since a given time?

journalctl -u <service> --since "2026-06-22 09:00", optionally adding -p err for errors or -f to follow.

📚Official Documentation

📝 My notes on this topic

Auto-saves as you type