less command stuck in forward scrolling

When piping command output into less, I’ll scroll to the bottom of the output using the mouse and I’ll find less gets stuck in forward scrolling, preventing me from scrolling back through output. This is the same behaviour as pressing F. Is there a way to unlock less from forward scroll?

Reproduce: docker-compose up | less followed by pressing F.

Answer

Yes.

I believe less actually says “Waiting for data… (interrupt to abort)” upon entering this mode, at least when the left hand side of the pipeline is not producing data fast enough.

“Interrupt” means “Press Ctrl+C“. This will send the INT (interrupt) signal to the less process.

Ctrl+C will send the INT signal to whatever program currently is in the foreground in the shell, just like doing kill -s INT pid from another terminal would do (where pid might be the process ID of the less process, for example). Fun fact.

To avoid sending the interrupt signal to the data-producing command on the left hand side of the pipeline, you could make that command ignore that signal completely:

( trap '' INT && some-command ) | less

Attribution
Source : Link , Question Author : retrohacker , Answer Author : Kusalananda

Leave a Comment