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.
3 Answers
After a bit of playing around I've discovered that you can:
triple-clickthe last line- hit shift + home
- shift +
clickfirst 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)
script command is appropriate when you want to save a terminal session to a file and display it later. When you call script it launches your shell, and when you are done, just type in exit. Everything will be in typescript file unless you specify otherwise.
For instance,
xieerqi:$ echo "Hello, Karl Wilbur"
Hello, Karl Wilbur
xieerqi:$ date
2015年 10月 27日 星期二 11:38:15 MDT
xieerqi:$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 115247656 80939384 28430924 75% /
none 4 0 4 0% /sys/fs/cgroup
udev 2914832 4 2914828 1% /dev
tmpfs 585216 1100 584116 1% /run
none 5120 0 5120 0% /run/lock
none 2926072 328 2925744 1% /run/shm
none 102400 52 102348 1% /run/user
xieerqi:$ exit
Script done, file is typescript
xieerqi@eagle:~$ cat typescript
Script started on 2015年10月27日 星期二 11时37分55秒
xieerqi:$ echo "Hello, Karl Wilbur"
Hello, Karl Wilbur
xieerqi:$ date
2015年 10月 27日 星期二 11:38:15 MDT
xieerqi:$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 115247656 80939384 28430924 75% /
none 4 0 4 0% /sys/fs/cgroup
udev 2914832 4 2914828 1% /dev
tmpfs 585216 1100 584116 1% /run
none 5120 0 5120 0% /run/lock
none 2926072 328 2925744 1% /run/shm
none 102400 52 102348 1% /run/user
xieerqi:$ exit
Script done on 2015年10月27日 星期二 11时38分18秒There may be control characters in the typescript file though ,such as from the ls comand, so use cat typescript | col -b > outputfile.txt command to redirect clean output to file
You can do this after the fact as well. You're looking for Virtual Console Memory (man vcs contains more info and a couple of examples).
In your case, if you're is working on a virtual terminal trough /dev/tty1, the following snippet will let you store the backlog in a file output-file:
cat /dev/vcs1 >output-fileNote that the device numbers of tty1 and vcs1 match.
Edit: I should note that this only works for virtual terminals and not for pseudo terminals (pseudo terminals are used to implement terminal emulators like gnome-terminal, xterm etc see man pts for more info).