Logs GNU Screen – How to Save Past GNU Screen Output to a File

gnu-screenlogs

I have had a GNU screen session running for days. I find myself in the situation that I need to save the terminal contents (which I can scroll up to see) into a file. Is this possible? I estimate it to be below 5000 lines.

I found a way to set up screen to log future output to a file. But in this case, I need to also save past output (or as much of it as is present).

Best Answer

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.

Related Question