Copying the GNU screen scrollback buffer to a file (extended hardcopy)
Keyboard ShortcutsGnu ScreenKeyboard Shortcuts Problem Overview
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?
Keyboard Shortcuts Solutions
Solution 1 - Keyboard Shortcuts
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.
Solution 2 - Keyboard Shortcuts
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.
Solution 3 - Keyboard Shortcuts
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
Solution 4 - Keyboard Shortcuts
Try hardcopy -h
to include the whole buffer.
Solution 5 - Keyboard Shortcuts
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%.
Solution 6 - Keyboard Shortcuts
Ctrl + A, :, and issue the command 'log on'.
Or set it as the default in your .screenrc file as 'deflog on'.
Solution 7 - Keyboard Shortcuts
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.