Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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