8

An interesting annoyance that just plagued a coworker:

If you less a file that's being appended to, you can hit shift-f to start following the output stream in real time. Then, to stop following the output, you hit ctrl-c, after which you can navigate and search the file as usual.

This does not work when using journalctl. Say you want to follow your nginx log - you'd run journalctl -u nginx, and then the usual shift-f to start following the output. However, when you press ctrl-c, less immediately terminates, rather than exiting the "follow" mode and returning to "navigation" mode as it does when following a file.

Needless to say, this is incredibly annoying. Why is this, and how do I restore the normal functionality?

1
  • 4
    It's because of the default options that systemd passes to less (see man journalctl section Environment)... Same question as here... Commented Sep 12, 2016 at 16:18

1 Answer 1

4

As answered over on ServerFault, this is because less is invoked with the K flag, which causes it to die upon recieving a ^C character, rather than returning to its command prompt.

To remedy this, export the variable SYSTEMD_LESS="FRSXM" into your environment. This is the standard set of flags that systemd passes to less, minus the problematic K that makes it impossible to break out of follow mode.

1
  • 1
    With systemd 241 on Debian 10. I had to set both SYSTEMD_PAGER='less -FRSXM' and SYSTEMD_LESS='FRSXM'. Commented Nov 21, 2020 at 23:21

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.