7

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

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.

16
  • 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. Commented Feb 20, 2024 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. Commented Feb 20, 2024 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. Commented Feb 20, 2024 at 20:37
  • 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. Commented Feb 21, 2024 at 1:15
  • 1
    btw: I found option --no-tail very useful in combination with --follow. Commented Jul 22, 2024 at 17:46
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. Commented Feb 20, 2024 at 11:45
  • @StéphaneChazelas Ah, right, +command has to go after options. Commented Feb 20, 2024 at 11:56
  • But how can I refresh the logs while viewing? Commented Feb 20, 2024 at 20:28
  • @fire84392 watch might help, i.e. re-execute peiorically. Commented Feb 20, 2024 at 21:15
  • 1
    @fire84392 Read the watch manpage. Commented Feb 21, 2024 at 7:28

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.