When reading from stdin, less does not display any output until a whole line has been read.

I use a script that prints progress on one line, without printing a newline, and I would really like to be able to see this progress even when I pipe it to less.

Here is some example bash code to demonstrate my problem:

while true ; do echo -n zzz ; sleep 1s ; done | less

Is there a button I can press to force less to display its collected input, or is there an option to disable this kind of buffering?


I don't think it's possible.

You could instead filter the input to insert line breaks. Here's a very simplistic filter which doesn't take care of where it puts the line breaks; it's definitely possible to improve on that, but at least you'll see your output in near-real time.

perl -e '$| = 1; while (sysread STDIN, $_, 80) {print; /\n/ or print "\n"}

Alternatively, you could switch to another viewer. Emacs's shell mode is a heavyweight solution if you don't otherwise use Emacs. You would run the script in a *shell* buffer (created with M-x shell). Apart from the different interface, it can do all that less can do, and more, including showing the output as it comes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.