I had a program print lot of data on the terminal. The terminal scrolled over and now I cannot see all the data. Some of it is lost. How do I get it back ?

  • Once it's scroll out of the scroll buffer, it's gone. Re-run the program, and this time capture the output into a file. Use "./myprog | tee foo" so you can see it and capture it into a file at the same time. Nov 24 '10 at 20:11
  • I love mac's terminal, it stops following the last line, when you scroll... less is not an option?
    – khachik
    Nov 24 '10 at 20:16
  • Thanks but I am aware of tee command. I was more interested in techniques to get data that scrolled out of the screen.
    – abc
    Nov 24 '10 at 20:18

You can use various strategies to save the output of programs that print a lot of data:

  1. Press Shift+PageUp to scroll up and view old output. If you've already run the program then this is your only option, and you'll be limited by your terminal's scrollback buffer.

  2. If you know ahead of time there will be many screenfuls of output then use a pager to view a screenful at a time: command | less. less saves all the output in a buffer and lets you scroll up and down at your leisure.

  3. Redirect the output to a file: command > /tmp/output.txt.

  4. When doing #2 you can view the log file in real time with tail -f /tmp/output.txt. This will display the file as it is written to.

  5. Save the output to a file while still displaying it on screen: command | tee /tmp/output.txt. tee will duplicate its input, writing both to a log file and to stdout.

  • Pageup works just fine, or I could use my mouse to scroll the scroll bar. But I could not get the data that scrolled out of the scroll buffer.
    – abc
    Nov 24 '10 at 20:16
  • 1
    Once it's out of your scrollback buffer it's game over, man. Nov 24 '10 at 20:18
  • I am aware of other techniques using tee, >, less, more, cat etc. "Once it's out of your scrollback buffer it's game over" ...Thats the answer I was looking for. Thanks.
    – abc
    Nov 24 '10 at 20:19

If you know how to compile a kernel you can activate the following option in the kernel configuration and let the kernel save the scrollback buffer in RAM instead of the VRAM. You can also set the buffer size. There is practically no limit to scrolling back then because even 1MB will give you about 256 pages of scrollback.

You can find the option in:

Device Drivers -> Graphics support -> Console display driver support -> VGA text console -> Enable Scrollback Buffer in System RAM (CONFIG_VGACON_SOFT_SCROLLBACK)

Alternatively you could use screen that doesn't depend on the kernels buffer and has its own. The same applies to terminal emulator you use in X like Terminal, konsole or xterm.

  • I don't want to compile the kernel. screen has -h num that specifies the history scrollback buffer to be num lines high. However I was looking for an option to recover the lines that scrolled off. There is none !
    – abc
    Nov 24 '10 at 22:50
  • Yes that is correct, because there are not in memory anymore.
    – problemofficer
    Nov 25 '10 at 0:23

While you can't get it back once it's out of the window, you can capture it into a file next time you run it.

To just pump it into a file: ./program > path/to/file

To see it and put it in a file: ./program | tee file

  • This is also useful for creating files from the command line: cat > /path/to/file Nov 24 '10 at 20:15
  • Thanks but I am aware of redirecting o/p to files. I was more interested in techniques to get data that scrolled out of the screen.
    – abc
    Nov 24 '10 at 20:17
  • Nah, sorry, dude. It only saves the last X lines. After that it's goner than gone. Nov 24 '10 at 20:19

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.