Breaking out of follow mode with less and journalctl

journalctlless

An interesting annoyance that just plagued a coworker:

If you less a file that's being appended to, you can hit shiftf to start following the output stream in real time. Then, to stop following the output, you hit ctrlc, 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 shiftf to start following the output. However, when you press ctrlc, 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?

Best Answer

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.

Related Question