Save past GNU screen output to a file

One way to do it is to use copy mode to copy the entire scrollback history, then dump it into a file. (There is likely a better way.)

With default keybindings, this would be something like:

  • Ctrl-A to send screen a command
  • [ to enter copy mode
  • g to go to the top
  • Space bar to mark the beginning of the scrollback buffer (where you are) as the start of the text to be copied
  • G to go to the end
  • Enter to mark the end of the text to be copied, and copy it.

Then open up vim, run :set paste to avoid issues with e.g. auto-indentation, and then use Ctrl-A ] to paste.


You can use hardcopy -h command to save the contents of the current scroll buffer to a file. As described in man screen:

   hardcopy [-h] [file]

   Writes out the currently displayed image to the file file, or,
   if no filename is specified, to hardcopy.n in the default
   directory, where n is the number of the current window.  This
   either appends or overwrites the file if it exists. See below.
   If the option -h is specified, dump also the contents of the
   scrollback buffer.

You said:

I estimate it to be below 5000 lines.

5000 lines is really a lot. The default length of scroll buffer in screen is just 100, not ~5000 lines. Unless you started your screen session with a larger scroll buffer setting it will not be possible to retrieve all ~5000 lines of the scroll buffer.