79

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
  • 86,445
  • 63
  • 260
  • 306
T. Brian Jones
  • 945
  • 1
  • 7
  • 8
  • `history | less`, `more`? Or you are asking how to keep more history? –  Jun 28 '11 at 19:47
  • `history` will keep only commands have been fired in shell. He is more asking about logging sort of stuff –  Jun 28 '11 at 19:49
  • `` + `` is the only option. And it has some limit as well (at most last 500 lines, I guess). – ssapkota Jun 28 '11 at 19:51
  • 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 for me. – T. Brian Jones Jun 28 '11 at 19:52
  • 3
    Just `Ctrl-a` is `screen`'s escape. The whole key sequence to enter scrollback mode would be `Ctrl-a` `[`, as opyate says. `Ctrl-a` `ESC` also works for me, I don't remember which one is standard / commonly used. – ninjalj Jun 28 '11 at 20:01
  • See also this question: https://stackoverflow.com/questions/8760346/how-do-i-increase-the-scrollback-buffer-in-a-running-screen-session – tuxayo Sep 22 '18 at 16:47

8 Answers8

114

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
  • 1,914
  • 2
  • 14
  • 9
39

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
  • 5
William Pursell
  • 1,563
  • 10
  • 16
  • 8
    This is just plain wrong. The answer by @opyate does provide a solution – nirvana-msu Jul 04 '17 at 15:23
  • 8
    @nirvana-msu Using ^a to enter scrollback mode allows you to page up the scrollback buffer. If data is already gone from the scrollback buffer, it is gone. You can increase the size of that bufer at startup. What exactly about my answer do you think is incorrect? I talk about increasing the size of the scrollback buffer, opyate gives details on how to use it. – William Pursell Jul 04 '17 at 19:02
  • 3
    Well, ok, though the question wasn't really about extending scroll buffer. The author wanted to view more history than what's normally shown in console, and you _can_ view more history using `Ctrl+a+[`. Your answer just makes it seem like it's not possible, which is misleading. – nirvana-msu Jul 04 '17 at 19:08
  • This is not working on a mac. The other answers are not working neither. – bomben Oct 04 '19 at 07:20
19

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
  • 20,384
  • 48
  • 186
  • 322
  • Not working on a Mac. None of the answers work here. I still can just see the size of the Terminal window. Further up is just the `screen` command and the stuff I did before screen. I also tried `screen -h`, same result. Any ideas? – bomben Oct 04 '19 at 07:24
  • @Ben sorry no idea, I only tried on Ubuntu. – Franck Dernoncourt Oct 04 '19 at 07:25
  • 2
    Ah, it does work with `control` + `a` and then `ESC` and then I am able to scroll inside the text with the cursor. What does not work is scrolling with the mouse using the Mac Terminal sliders on the side. Thanks! – bomben Oct 04 '19 at 07:34
  • Bomben's answer make this more accurate in termcapinfo line add '\*' after xterm. That is `termcapinfo xterm* ti@:te@` you may find (as I did on Ubuntu) that my terminal type is `xterm-256color` And terminal inside of screen is of type `screen.xterm-256color`. So perhaps even use `*xterm*` to ensure nesting of screens works. – user377178 Feb 21 '22 at 17:30
  • Oh sweet, thanks for that termcapinfo! – resi Apr 22 '22 at 08:48
9

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
  • 386
  • 2
  • 7
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.

Seth Robertson
  • 582
  • 3
  • 5
1

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
  • 232
  • 2
  • 13
0

Ctrl + A, followed by Esc

also enters the copy/scrollback mode of screen.

Serge Stroobandt
  • 2,055
  • 1
  • 28
  • 25
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