Making peace with journalctl
Journalctl is systemd’s much-maligned replacement for syslogs. Crusty old nerds like me are mad it’s not just a text file. But the binary format actually has a lot of advantages, you can efficiently do simple time and metadata queries. I also like the color pager it gives you. Now that I’ve learned a bit about the journalctl tool I like it more.
journalctl -b
Entries since last boot. Solves the big problem of journalctl spamming you with useless crap from months ago. journalctl -b -1 will show you the boot before this one.
journalctl -n 100
Last 100 entries
journalctl --since '3h ago' --until '2h ago'
Time slicing. The since and until format is defined in systemd.time(7).
journalctl -u chrony or journalctl -t chronyd
Entries matching a unit name or syslog identifierjournalctl -g chrony
Entries whose contents match a grep expression. Note this does not match the displayed text of the metadata, it’s not the same as grepping a syslog.
journalctl -p 4
Level warning or more serious. The levels are the same as old syslog.journalctl -r
Reverse order.
journalctl -e
Jump the pager to the end (like pressing G).
journalctl -n 100 -f
Display the last 100 entries and keep scrolling new entries forever
journalctl --vacuum-time=7d
Erase all logs more than a week old. Useful for making disks smaller.
journalctl --dmesg
Emulate dmesg, only showing kernel messages (but in a different format).
usermod -aG systemd-journal nelsonAnyone in group systemd-journal can run journalctl without being root, at least on Debian. Note this includes the ability to modify the journal.
The big thing missing is negative filters. I want to show all log entries that are not from the spammy sshd and cron units. Can’t really do it.
You can still do journalctl | grep of course. There’s also a JSON output format you can manipulate with jq or the like.