brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: journalctl -g searches log messages with a regular expression

Journalctl
~/tips/tip-journalctl-grep-pattern-flag

journalctl -u ssh -g "failed|invalid user" --since yesterday

Filters journal messages with a regular expression and keeps the timestamps and paging.

Piping to grep loses the metadata and the paging, so I let journalctl do the matching.

journalctl -u ssh -g "failed|invalid user" --since yesterday
journalctl -b -g "error" --case-sensitive

-g (--grep) matches the message text against a PCRE2 regular expression and prints only the hits, with the usual timestamps. If the pattern is all lowercase the match ignores case, and a pattern with a capital letter is case sensitive. --case-sensitive forces exact case even for an all-lowercase pattern, as in the second line. It works with every other filter, so combine it with units and time ranges. It needs a journalctl built with PCRE2 support, which Debian and Ubuntu packages have.

Further reading: journalctl manual page

More Journalctl tips journalctl -k -g 'killed process' --since "2 days ago" journalctl _PID=1 -b ls -lh /var/log/journal/*/*.journal~ Storage=volatile sudo journalctl --setup-keys All Journalctl tips (81) All topics

Link