Progress: 0/62 (0%)

πŸ“‹ Viewing Logs

Viewing Logs

Think of logs like your system's diary. Every event, error, or action gets written down so you can figure out what happenedβ€”like checking office CCTV or a meeting log after something goes wrong. There are two main ways to view logs in Linux: log files in /var/log/ and journalctl.

Exploring /var/log/ Files

/var/log/ is a directory where most system logs live.

Common log files:

  • /var/log/syslog β†’ general system messages (like office memos)
  • /var/log/auth.log β†’ login attempts and authentication events (security diary)
  • /var/log/kern.log β†’ kernel messages (low-level system operations)
  • /var/log/dmesg β†’ hardware messages from boot (hardware check records)

How to view logs:

cat /var/log/syslog

# print entire file

less /var/log/syslog

# scroll through easily

tail -f /var/log/syslog

# watch live updates in real-time

The tail -f command is like having a live CCTV feed for your system events.

Using journalctl

journalctl is for modern Linux systems (systemd) where logs are kept in a centralized binary journal.

journalctl

# view all logs

journalctl -u ssh

# logs for ssh service only

journalctl -f

# live updates like `tail -f`

journalctl --since "1 hour ago"

# logs from last hour

Extra tip: You can combine filters, like journalctl -u nginx -p err to see only nginx errors.

Pro Tip

Logs are huge, so don't just scroll blindly. Use filters, timestamps, and service names to pinpoint problems quickly. Logs are your best friend for troubleshooting!

Real-life analogy

For /var/log/: Imagine a filing cabinet where every drawer stores a different type of record: security events, application logs, or system errors. For journalctl: Instead of separate notebooks for each log, all events are recorded in a master diary you can query efficiently. This gives you the "detective tools" to see what's happening inside your system at any moment.