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 combined with -n shows the newest matches first

Journalctl
~/tips/tip-journalctl-grep-with-lines-newest

journalctl -g timeout -n 5

Combining a text search with a line count prints the newest matches first, because the order flips.

This one surprised me, because the order flips without any flag saying so.

When -g is used together with -n, journalctl implies --reverse. The command above therefore prints the five most recent lines that contain timeout, newest on top. Without -n you get the whole history in the usual oldest-first order.

journalctl -g timeout -n 5

If you pipe the result into a script that expects oldest first, add -n +5 or sort it yourself. The reverse order only applies when -n is a plain number.

Further reading: journalctl(1) 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