Searching logs
journalctl filters, grep tricks and live tailing: find the relevant lines fast instead of scrolling.
journalctl cheat sheet
| What | Command |
|---|---|
| Log of one service | journalctl -u nginx |
| Several services | journalctl -u nginx -u php8.3-fpm |
| Follow live | journalctl -u nginx -f |
| Last 50 lines | journalctl -u nginx -n 50 |
| Newest first | journalctl -r |
| Jump to the end in the pager | journalctl -e |
| Since this boot / previous boot | journalctl -b / journalctl -b -1 |
| List boots | journalctl --list-boots |
| Time range | journalctl --since "1 hour ago" / --since "2026-10-21 08:00" --until "09:00" |
| Only errors and worse | journalctl -p err |
| Kernel only | journalctl -k |
| By program name | journalctl -t sshd or journalctl _COMM=sudo |
| By user ID | journalctl _UID=1000 |
| Search text (grep built in) | journalctl -u ssh -g "Failed password" |
| Print without the pager | journalctl -u nginx --no-pager |
| Short, one line per entry | journalctl -o cat (message only) |
Filters combine: journalctl -u ssh -p warning --since today -g "invalid".
Priorities for -p: emerg, alert, crit, err, warning, notice, info, debug. Each includes everything more severe.
Text logs
| What | Command |
|---|---|
| Follow live | tail -f /var/log/syslog |
| Follow several files | tail -f /var/log/nginx/*.log |
| Follow and filter | tail -f /var/log/syslog | grep -i error |
| Read with search | less /var/log/syslog, then /word, n next, G end |
| Live-follow inside less | less +F file (Ctrl+C to scroll, F to follow again) |
| Search current + rotated logs | zgrep -h "error" /var/log/syslog* |
| Hits with context | grep -C 5 "panic" /var/log/syslog |
| Lines from a time window | grep "Oct 21 08:1" /var/log/syslog |
Quick tips
Count instead of reading. Which errors happen most often?
journalctl -p err -b -o cat | sort | uniq -c | sort -rn | head
Which IPs fail to log in most?
grep "Failed password" /var/log/auth.log | grep -oE "from [0-9.]+" | sort | uniq -c | sort -rn | head
Top requesters in an nginx access log:
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
Reproduce while watching. Open a second SSH session with journalctl -f (everything) or journalctl -u SERVICE -f, then trigger the problem in the first one. You see exactly which lines appear.
Start at the first error, not the last. Later errors are often just consequences. Use journalctl -u SERVICE -p err --since "10 min ago" and read from the top.
Note the time. Write down when the problem happened, then use --since / --until around it.