1. Understanding Linux Logging Systems

journalctl is a tool to interact with journald which is an in-built tool in systemd. It helps logging easy and accessible because it was stored in binary format managed by journald. But, the traditional logs are stored in plain text files under /var/log/.

  • systemd Journal

It centralizes logs in a binary format managed by journald, accessible via journalctl. Offers advanced filtering, real-time updates, and more context.

  • Traditional Logs

Stores logs in a plain text files under /var/logs/. We have to use external tools like grep, tail, and less for analysis. It is still functional, but very old and there’s no advanced filtering.

2. Using journalctl to View and Filter Logs

journalctl

  • Centralizes logs from the kernel, systemd, and services in a structured, searchable binary format.
  • Provides advanced filtering, real-time monitoring, and boot-specific logs.
  • Designed to overcome the limitations of tradition plain-text logging by offering more context and metadata.

Subcommands and Essential Commands

CommandDescription
journalctlView all system logs (Chronological Order)
journalctl -rView logs in reverse chronological order (newest first)
journalctl -n NShow the last N entries
journalctl -kShow only kernel messages
journalctl -p LEVELFilter by log priority(e.g: error or 3)
journalctl -u UNITFilter by systemd unit/service(e.g: apache2.service)
journalctl -fFollow logs in real time (aka tail -f)
journalctl --since TIMEShow logs since a specific (Time) Sun Jun 22 14:44:52 2025
journalctl --until TIMEShow logs until a specific time
journalctl --disk-usageShow disk usage of journal logs
journalctl --vacuum-size=SIZEReduce logs size to specific amount
journalctl _SYSTEMD_UNIT=UNITFilter by systemd unit using field (aka -u)
journalct _UID=UIDFilter by user ID

Traditional Logs

  • Stores traditional system logs in plain text files.
  • Used for compatibility with tools and scripts.
  • Allows quick access to logs for specific applications or subsystems
  • Not as much flexible as journald

Subcommand and Essential Commands

Log FileDescription
/var/log/message/General System Messages
/var/log/syslog (Debian*)System Logs for Debian based distro and it’s similar to message
/var/log/auth.logLogin attempts, sudo, ssh (/var/log/secure on RHEL/Fedora)
/var/log/kern.logKernel Messages
/var/log/dmesgBoot-time Kernel Messages
/var/log/httpd/, /var/log/nginx/Web Server Logs

Example

  1. View all system logs
journalctl
  1. View logs in reverse order
journalctl -r
  1. Show only kernel messages
journalctl -k
  1. View logs from the current boot
journalctl -b
  1. Filter by priority (Error and Above)
journalctl -p err
# other flags: emerg,alert,crit,warning,notice,info,debugs
  1. Filter by service
journalctl -u ssh.service
  1. Show last 20 log entries
journalctl -n 20
  1. Output in SON format
journalctl -o json-pretty
  1. Monitor logs in real-time
journalctl -f
  1. Investigate failed login attempts
journalctl | grep -i "failed password"
journalctl -u ssh.service | grep -i "failed password" #show failed login attempts for specific service
  1. Track system errors over time and period
journalctl  --since "2025-06-24 08:08:08" --until "2025-06-24 17:17:17" -p err

Mostly useful for post-analysis

  1. View logs for a specific user
journalctl _UID=$(id -u)
  1. Export logs for analysis
journalctl --since yesterday > textFile_logs.txt
  1. Filter by Process ID
journalctl _PID=<pid>