ubuntu, updated

Searching logs

journalctl filters, grep tricks and live tailing: find the relevant lines fast instead of scrolling.

journalctl cheat sheet

WhatCommand
Log of one servicejournalctl -u nginx
Several servicesjournalctl -u nginx -u php8.3-fpm
Follow livejournalctl -u nginx -f
Last 50 linesjournalctl -u nginx -n 50
Newest firstjournalctl -r
Jump to the end in the pagerjournalctl -e
Since this boot / previous bootjournalctl -b / journalctl -b -1
List bootsjournalctl --list-boots
Time rangejournalctl --since "1 hour ago" / --since "2026-10-21 08:00" --until "09:00"
Only errors and worsejournalctl -p err
Kernel onlyjournalctl -k
By program namejournalctl -t sshd or journalctl _COMM=sudo
By user IDjournalctl _UID=1000
Search text (grep built in)journalctl -u ssh -g "Failed password"
Print without the pagerjournalctl -u nginx --no-pager
Short, one line per entryjournalctl -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

WhatCommand
Follow livetail -f /var/log/syslog
Follow several filestail -f /var/log/nginx/*.log
Follow and filtertail -f /var/log/syslog | grep -i error
Read with searchless /var/log/syslog, then /word, n next, G end
Live-follow inside lessless +F file (Ctrl+C to scroll, F to follow again)
Search current + rotated logszgrep -h "error" /var/log/syslog*
Hits with contextgrep -C 5 "panic" /var/log/syslog
Lines from a time windowgrep "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.

§ home
~/knubertus/home/
1,1 Top