85

I was running scripts overnight from the command line (inside Screen on a Linux EC2 instance) and some errors that I was not tracking occurred. I want to "scroll up" or view more of the history in Screen, but I cannot seem to find any commands that will work.

I need to see the onscreen output "further up" than I can on my current screen. CTRL + a is supposed to put me into scroll mode inside Screen, but it's not working.

Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311

8 Answers8

122

Assuming you haven't overriden your escape sequence, you can press Ctrl-a [ to go into scrollback mode, then use the usual Page-UP/Page-DOWN or Ctrl-b/Ctrl-f to go up and down.

From the Gentoo wiki on Screen usage

opyate
  • 2,024
44

When you start screen you can specify the size of the scrollback buffer with -h, so you can increase it from the default of 100 lines. However, with a currently running screen, once the data has left the buffer, it is gone.

[edit for clarity]
@opyate explains how to use the scroll back buffer in his answer. I copy that answer here as it give more clarity and improves this answer for newcomers.

Assuming you haven't overriden your escape sequence, you can press Ctrl-a [ to go into scrollback mode, then use the usual Page-UP/Page-DOWN or Ctrl-b/Ctrl-f to go up and down.

daco
  • 103
24

I need to see the onscreen output "further up" than I can on my current screen. CTRL + a is supposed to put me into scroll mode inside Screen, but it's not working.

In complement to the other answers, I would point out that you may add in your ~/.screenrc file:

defscrollback 100000
termcapinfo xterm ti@:te@

where:

  • defscrollback 100000: set the default number of scrollback lines to 100000
  • termcapinfo xterm ti@:te@: allow terminal scrolling in either xterm or PuTTY. (screen FAQ; PuTTY FAQ)
Franck Dernoncourt
  • 24,246
  • 64
  • 231
  • 400
11

You can also change the scrollback history size in a running screen with the sequence CTRL-a : (enter screen command-line mode), then scrollback 10000 if you want 10k lines of history buffer. The change applies immediately.

Be careful of memory usage if you use many screens with very long buffers.

However, like @William Pursell said, with a currently running screen, once the data has left the buffer, it is gone.

Saïmonn
  • 426
7

You can also run your commands in the script command which will log the output to disk. Or you can: command 2>&1 | tee /tmp/cmd.out to log the output for future investigation in you wanted a (practically) infinite sized output history.

2

Using a macOS Terminal I was not able to use the sliders at the side to see text history.

I was able to scroll with the cursor inside the text using ↑ and ↓ after I hit CRTL + a and then ESC.

And I had to add this to ~/.screenrc to enable mouse scrolling from inside the window (still not with the sliders):

termcapinfo xterm* ti@:te@
bomben
  • 272
1

Ctrl + A, followed by Esc

also enters the copy/scrollback mode of screen.

0

Depending on what terminal program you are using, you can usually change the Scrolling Buffer under Settings. I know for xterm you have to enable Scrolling first, then you can set the buffer to infinite.

Your best bet however for logging scripts would be to Re-direct the standard output to a file:

ScriptName >> OutputFile.txt

Doing it this way you can scroll and search freely as well as keep a record (i.e. in case your computer crashes).

EDIT: This is close to the piping solution above, however redirecting standard input can be useful in other instances as well:

grep linux stackoverflow.txt > linuxquestions.txt

or

cat linuxquestions.txt | grep buffersize > bufferquestions.txt