208
votes

How do I easily copy the GNU Screen scrollback buffer to a file? I.e., a more powerful version of the 'hardcopy' command?

In GNU screen, I can use "Ctrl + A Esc" to enter the scrollback buffer. I could then mark the entire buffer and use "Ctrl + A Ctrl + ]" to paste it into an Emacs buffer, thus saving it to a file.

However, this is tedious. Is there a Screen command that'll simply copy the scrollback buffer to a file, like 'hardcopy' does for the visible portion of the screen?

7

7 Answers

315
votes

To write the entire contents of the scrollback buffer to a file, type

Ctrl + A and : to get to command mode, then

hardcopy -h <filename>

In older versions of screen, if you just do hardcopy -h, it just writes to the file -h. This was fixed in version 4.2.0, so hardcopy -h writes to hardcopy.N where N is the current window number.

26
votes

Press Ctrl+A :bufferfile /tmp/somefile.txt ENTER, and then Ctrl+A >

This will write the current contents of the buffer to the named file.

13
votes

TL;DR: ^A:writebuf <filename>

The OP seems to want a way to use the selected portion of the buffer you get when doing a ^A[ , selecting text using space as the start and finish, and then instead of using ^A] to paste, save the resulting selected portion of the buffer to a file.

This worked:

^A:writebuf <filename>

Note: one 'f' in writebuf

6
votes

Try hardcopy -h to include the whole buffer.

4
votes

This worked for me:

Enter edit mode (~) and type:

:hardcopy -h buff_file

It created a huge file, of which 98% was empty, but my logs were fully present in remaining 2%.

-1
votes

Ctrl + A, :, and issue the command 'log on'.

Or set it as the default in your .screenrc file as 'deflog on'.

-3
votes

Do Ctrl + A, H.

That saves the current screen into a hard copy file, e.g., hardcopy.0 for screen 0. It seems to be a quicker way than going Ctrl + A, : and typing the hardcopy command.