I have a script that runs for a long time. It has plenty of output to stdout that I would like to be able to read over in real time but also scroll up and down. Whenever a new line of output is printed to stdout, my screen resets to the bottom of the output (most current content). Is there any way to page through stdout while also having the newest content visible and up-to-date when I scroll down?

I'm on RHEL7. I don't have a GUI and am connected to the host via SSH.

  • 2
    Pipe it to less! command | less Mouse may or may not work in less, make sure to use page up & down if not. Commented Feb 8, 2019 at 7:38
  • In addition to less (which is the best answer to this). I would also recommend screen or tmux which if configured correctly will let you scroll the output
    – KNejad
    Commented Feb 8, 2019 at 9:07

1 Answer 1


You may use a pager such as less:

program | less

or, if you also want to save the output to a file:

program | tee logfile | less

Within less, you may scroll back and forth, and you may get a tail -f behaviour by pressing F (press Ctrl+C to get out of this mode). You can even start it up in this mode:

program | tee logfile | less +F

To avoid possibly blocking the writes from you program, make the program redirect directly to an output file in the background and then use less on that:

program >logfile & 
less logfile 

See the manual for less on your system.

  • 2
    As far as I can tell, less reads some amount of data at first, and then doesn't read more unless you scroll to the end. So there's a chance here that the main program will block on the pipeline if the output is very long. To deal with that, it's probably best to just direct the output to a file and run less on that.
    – ilkkachu
    Commented Feb 8, 2019 at 9:03
  • @ilkkachu Good point, added.
    – Kusalananda
    Commented Feb 8, 2019 at 9:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .