Bash – Save or capture Screen output to file after it has written to stdout

bashgnu-screen

I've run a script in a screen session but I forgot to redirect stdout to a file. There's about 10MB worth of text. If there's even some way to highlight the text and copy paste I would, but Ctrl-A + Esc won't scroll my terminal view when I click and drag the mouse. I'm using bash on Ubuntu 18. Is there anything I can try?

Best Answer

So the usual scroll back buffer isn't going to hold that much data so you're likely SOL. Sorry.

That being said, screen has it's own scroll back buffer that is separate from your terminal (and hence click and drag). What you want to do is:

  1. ctrl-a and then [ (left bracket). This will enter screen's copy mode (or whatever they call it).
  2. Screen uses vi keys to move the cursor around. Move the cursor to the end of your output.
  3. Hit space. This starts select
  4. Move the cursor as far back in history as there is (it will scroll as you move up).
  5. Hit space again. This completes the selection and exits copy mode.
  6. Run cat > save_file.txt or the like
  7. ctrl-a and ] (right bracket)
  8. ctrl-d End of file. What was pasted should be in save_file.txt

If you don't know vi keys skip #2 and do ctrl-b as long as it scrolls for #4.