330

I use screen for my command-line tasks while managing the servers where I work. I usually run small commands (mostly file-system tasks) but sometimes I run more extensive tasks (like DBA).

The output of those tasks is important to me. Since I use Ubuntu and OS X (both Terminal Windows) for my tasks, yet I need to use screen, the scrolling is not available, so any long output (think a 500-row table from a select) is invisible for me. Mouse-wheel is out of the question.

When I say "scroll is invisible for me, I mean this:

top while using screen, in Mac OS X, while scrolling

I was thinking about two options:

  1. Pause (think paginate) the output of a certain command. When the output begins, it would let me read what's happening, then I press "Enter", then the output continues until there's nothing more to show.

  2. Scroll inside screen. But I don't know if this is possible.

Of course, I don't know if those options are actually possible. If they are, how can achieve them? Other alternatives will be well received.

450

Screen has its own scroll buffer, as it is a terminal multiplexer and has to deal with several buffers.

Maybe there's a better way, but I'm used to scrolling using the "copy mode" (which you can use to copy text using screen itself, although that requires the paste command too):

  • Hit your screen prefix combination (C-a / control+A by default), then hit Escape.

  • Move up/down with the arrow keys ( and ).

  • When you're done, hit q or Escape to get back to the end of the scroll buffer.

(If instead of q or Escape you hit Enter or Return and then move the cursor, you will be selecting text to copy, and hitting Enter or Return a second time will copy it. Then you can paste with C-a followed by ].)

Of course, you can always use more and less, two commonly used pagers, which may be enough for some commands.

  • 5
    Also, pressing q quits copy mode without copying anything (and it's one less button press). This might be in the vi explanation but the link is now broken. – Nathanael Farley Jun 26 '14 at 8:59
  • 3
    Also pressing [Esc] exits from copy mode too. – Sopalajo de Arrierez Oct 6 '15 at 21:06
  • 7
    any way to page-up? – Sungguk Lim Oct 29 '16 at 2:47
  • 9
    Scroll buffer seems to support vi-like commands: C-b and C-f for scrolling page up/down. – Touko Jan 18 '17 at 7:30
  • 3
    In copy mode my PageUp and PageDown buttons work. First press only moves one line but after that it pages like normal. – Elijah Feb 28 '17 at 21:54
154

Using the screen buffer as pointed out by njsg is a good solution. You can also disable the alternate text buffer in the xterm termcap info inside screen. When disabled you can use the scroll bars (and mouse wheel) to scroll up and down.

Add this to your ~/.screenrc.

# Enable mouse scrolling and scroll bar history scrolling
termcapinfo xterm* ti@:te@

You can read more discussion here.

  • 1
    set scrollback limit by typing Ctrl+A, :, type "scrollback 10000" or whatever numeric value you want – lobi Nov 10 '16 at 22:20
  • 2
    Using this, the typical shortkeys of Linux terminals (shift+pg up/down home/end) also work, thanks. – tokland Nov 22 '16 at 10:02
  • 4
    This tip alone makes me reconsider using screen... – Fish Monitor Aug 18 '17 at 10:56
  • 4
    +1 More elegant than accepted solution. – Ryan Yoosefi Oct 23 '17 at 18:00
  • 7
    only gives you the output screen gave you since you started it - ie, reattaching elsewhere means you can't scroll up and see what happened prior. but you can still retrieve earlier output using the solution in the accepted answer - then you can use your mouse wheel again. – Phil Nov 2 '17 at 4:08
20

All these answers addressed how to navigate within a screen session, but there is a built-in functionality in screen command to store everything in a file through the -L argument according to the manual which reads:

-L tells screen to turn on automatic output logging for the windows.

so you can do:

screen -L -S testscreen

and it will create a file withe the screenlog.# where the # is a number for that screen starting from 0.

This has lots of advantages and the most important ones for me are:

  1. Keeping record of what i have done since I can save the log file in the project folder for future reference.
  2. You can inactively and passively monitor the process:
    • use tailf to monitor the progress in realtime without being attached to the screen.
    • use grep to check for certain term in the log and produce notifications (email, popup, voip, etc.). This can be applied on multiple screens without you actively looking at them.
3

I've had success getting basic paging by piping content to more, for example:

ls -l | more

Or, if you want color output for use cases like syntax highlighting, you can use

ls -l --color=always | more

This results in output that I can easily page through one screen at a time. I haven't tried @uther's modification to ~/.screenrc but that does seem preferable as a lasting solution when a mouse is available.

To try this out, you can go to this BusyBox emulator and then...

cd ~/bin
ls -l --color=always | more

Use the spacebar to page through the results of the ls -l command or use the enter key to move through results line by line.

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.