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 ?
You can use various strategies to save the output of programs that print a lot of data:
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.
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.
Redirect the output to a file:
command > /tmp/output.txt.
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.
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.
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.