Ubuntu – Save current terminal scrollback to file

command linegnome-terminal

I have been looking for an answer to this and not finding anything which makes me think it's not possible but …

Is it possible to save the current Gnome Terminal scrollback buffer to a file?

I know that I can do something like command > output.txt to redirect all output to a file, or command | tee output.txt to split the output to the terminal as well as to a file. What I am trying to do is capture this after the fact. I'd like to save the current terminal tab's scrollback contents to a file.

Best Answer

After a bit of playing around I've discovered that you can:

  • triple-click the last line
  • hit shift + home
  • shift + click first line
  • copy with ctrl + shift + c (or right-click > 'Copy')

Now paste it into a text file ...or, using xsel you can shove your clipboard into a new file by just popping open a new tab and doing:

xsel -o > out.txt

(To install xsel do sudo apt-get install xsel)