Shell – How to Exit less Follow Mode Without Stopping Other Processes in Pipe

job-controllesspipeshellsignals

Often times I find myself in need to have the output in a buffer with all the features (scrolling, searching, shortcuts, …) and I have grown accustomed to less.

However, most of the commands I use generate output continuously. Using less with continuous output doesn't really work the way I expected.

For instance:

while sleep 0.5
do
    echo "$(cat /dev/urandom | tr -cd 'a-zA-Z0-9' | head -c 100)"
done | less -R

This causes less to capture the output until it reaches maximum terminal height and at this point everything stops (hopefully still accepting data), allowing me to use movement keys to scroll up and down. This is the desired effect.

Strangely, when I catch-up with the generated content (usually with PgDn) it causes less to lock and follow new data, not allowing me to use movement keys until I terminate with ^C and stop the original command. This is not the desired effect.

Am I using less incorrectly? Is there any other program that does what I wish? Is it possible to "unlock" from this mode?

Thank you!

Best Answer

Works OK for me when looking at a file that's being appended to but not when input comes from a pipe (using the F command - control-C works fine then).

See discussion at Follow a pipe using less? - this is a known bug/shortcoming in less.