6

I'm using less to view my journalctl logs because it's more convenient. It doesn't clutter the console window with logs after you exit less and you can scroll using your mouse wheel.

journalctl --unit xyz | less +G

But it's very annoying that I cannot refresh the logs. Is there a way to do that with less? Using Shift + F doesn't work.

2 Answers 2

8

journalctl calls less anyway (on a typical system). It might be calling less with different options from what you'd like, but you can customize that through the SYSTEMD_LESS environment variable. The default is FRSXMK. You can set it to something like

export SYSTEMD_LESS='-M -R -S +G'
6
  • I find that I need SYSTEMD_LESS=RMS+G instead. Feb 20 at 11:45
  • @StéphaneChazelas Ah, right, +command has to go after options. Feb 20 at 11:56
  • But how can I refresh the logs while viewing?
    – fire84392
    Feb 20 at 20:28
  • @fire84392 watch might help, i.e. re-execute peiorically. Feb 20 at 21:15
  • 1
    @fire84392 Read the watch manpage. Feb 21 at 7:28
7

But it's very annoying that I cannot refresh the logs. Is there a way to do that with less? Using Shift + F doesn't work.

You might be looking for journalctl's, --follow/-f. That cancels the use of a pager by journalctl, so I guess you need to add it.

journalctl -fu xyz | less

Then less's Shift+F works to see new entries that are added while you're viewing in less.

If you want to scroll up in less while less is waiting for new input (because you hit Shift+F or simply scrolled to the bottom), then make sure to use Ctrl+X rather than Ctrl+C to interrupt its waiting for new entries. If you use Ctrl+C, that's going to kill journalctl so you wouldn't be able to get new entries afterwards.

Here's an example video. I hope this clarifies:

enter image description here

For Ctrl+X, you need to update to less version 633, released last May.

15
  • It doesn't seem to work. When I run journalctl -fu xyz | less the logs are updated live, but I cannot navigate using the arrow keys or scroll wheel.
    – fire84392
    Feb 20 at 20:22
  • @fire84392 Try pressing the F key, that's Shift+F for capital F, when hitting the bottom of the log. That should tell less to continue reading beyond the last recorded output. This won't be as seamless as the normal behavior of journalctl -f continuously showing new message as they arrive, but it's the best that less can do if you want to combine both.
    – penguin359
    Feb 20 at 20:29
  • Which steps do I have to follow? I run journalctl --unit xyz | less (without --follow), go to the bottom with G and press Shift+F? It doesn't work. It says Waiting for data... (interrupt to abort) but it doesn't update the logs. Also I cannot navigate anomore.
    – fire84392
    Feb 20 at 20:37
  • If I run journalctl -fu xyz | less like @JoL said, the logs get updated live. I don't have to press Shift+F and I cannot press Shift+F. It doesn't let me navigate or enter any commands. At the bottom of the console there's a blank line with a blinking caret. Usually there's a : and I can enter commands there.
    – fire84392
    Feb 20 at 20:42
  • 1
    @fire84392 You don't need to install less system-wide if you don't want to interfere with someone else's server. I assume you have your own user account on it. Install it under your normal user's home directory, probably using either $HOME/bin or $HOME/.local/bin as the path. Create the folder if it doesn't exist and make sure it gets added to the beginning of your $PATH when logged in by updating your ~/.profile or whatever is appropriate for your shell of choice. You just need to compile it on this system by running make, but don't need to run make install.
    – penguin359
    Feb 21 at 1:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .