How to show the full (historical) content of a screen session in Linux

Written by - 0 comments

Published on - Listed in Linux

The screen command is very helpful when you need to run long-time commands (such as upgrades) or you need to "share" the SSH session with another remote user. A dedicated Shell is running in the screen process, which can be detached and re-attached again.

Creating a new screen session

Let's create a new detached screen session named "upgrade":

ck@linux:~$ screen -dmS upgrade

We can find the detached screen session using screen -list:

ck@linux:~$ screen -list
There is a screen on:
    34002.upgrade    (07/06/2022 02:20:27 PM)    (Detached)
1 Socket in /run/screen/S-ck.

Re-attach the screen:

ck@linux:~$ screen -r upgrade

And we're now in a separate Shell inside the screen session:

Note: To detach from within a screen session, use the following keyboard combination: [CTRL]+[a] followed by [d].

We can now launch some commands which could take some time, such as upgrading the local packages. Before we do that, let's get some information about the current distribution.

Show OS related information

Now let's run the actual apt commands to update the local packages. We can now see that part of the output above (containing the information about the OS release) disappears:

(Re-)Attached to screen, can only see last few lines

At this point we have reached the relevant part of this blog article. When (re-)attaching a running screen session (using screen -r sessionname), only the last lines of output is shown. That number of lines actually depends on the current window size: A small terminal window only shows so much of the screen session output, a larger window shows more historical output.

To make this worse, there is no scrollbar available. Doesn't matter if you've been in the screen session since its beginning or (re-)attached to the session at a later point in time. When trying to scroll using using a wheel mouse, this is interpreted as character input and results in weird characters (^[[A) showing up in the screen session:

This is especially frustrating if you need to check the historical output from a screen session - usually the reason for running a process inside a screen session.

Scroll mode to the rescue!

But screen wouldn't deserve the name "screen" if it wouldn't have a solution to it. Just as in vim, there are certain keyboard combos that are not well known but completely change the meaning of the program.  In this case screen can be told to switch to the scroll mode. This can be achieved by using the following keyboard combination: [CTRL]+[a] followed by the "[" (square bracket) key. Depending on your keyboard layout, you may need to use the [AltGr] key to use the "[" key on the keyboard.

Scrolling up with the mouse now works, and so do the [Page Up] and [Page Down] keys.

Scroll mode in screen session

This way the whole screen session can be seen from begin to bottom once again.

Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.