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 still reads the .journal~ files that journald set aside

Journalctl
~/tips/tip-journalctl-tilde-files

ls -lh /var/log/journal/*/*.journal~

Understand the journal files with a tilde at the end and read them when needed.

If you look in /var/log/journal after a power cut, you may find a file whose name ends in .journal~. It looks like an editor backup, and I would have guessed it was safe to delete.

The systemd-journald man page explains it: when the daemon is stopped uncleanly, or a file is found to be corrupted, journald renames it with the .journal~ suffix and starts a new file. So these are the logs from right before a crash, which is often exactly what you want to read.

ls -lh /var/log/journal/*/*.journal~

journalctl picks them up along with the normal files. To look at them on their own, point it at the files directly:

sudo journalctl --file '/var/log/journal/*/*.journal~' -n 50

Both -D on a folder that holds such a file and --file with the pattern print its entries. The quotes keep your shell from expanding the glob, so journalctl does it.

The man page says journalctl should be able to read every entry that was fully written, so the very last lines before a crash can still be missing or cut. Run journalctl --verify --file=... on such a file if you suspect damage. Since these files are evidence of a problem, copy one somewhere safe before you start a vacuum.

Further reading: systemd-journald.service man page, journalctl man page

More Journalctl tips journalctl -k -g 'killed process' --since "2 days ago" journalctl _PID=1 -b Storage=volatile sudo journalctl --setup-keys journalctl -F _KERNEL_SUBSYSTEM All Journalctl tips (81) All topics

Link