9

On tty2, how do I take a text screenshot of the command line?

neverMind9
  • 1,690

3 Answers3

13

Did you consider the screendump command?

RudiC
  • 8,969
  • 3
    "Just saying cat /dev/vcsN has a similar effect". Then why not just use cat /dev/vcsN? – Weijun Zhou Nov 24 '18 at 16:45
  • 5
    Try it and see. – RudiC Nov 24 '18 at 16:46
  • Nice. Is there a way to get it to do colour as well? (screendump reads from /dev/vcsa devices which does have colour information, but it seems to be stripped from the output.) Btw. I like to combine it with the watch command to see live output like watch -n0.1 screendump. – kasperd Nov 25 '18 at 13:25
  • @WeijunZhou /dev/vcs devices don't contain information about the size of the screen, so cat /dev/vcsN only works if your terminal window has the same number of characters across as the VC you are capturing. – kasperd Nov 25 '18 at 13:26
4

If you can use tmux or screen, they have the ability to save the scrollback buffer to a file.

Unlike screendump, which is Linux-only, tmux and screen are available for BSD-based OSes too (e.g. macOS, FreeBSD) and won't require special permissions.

jamesdlin
  • 838
  • Because of that, I marked this one as accepted. But @RudiC Don't take it personally. Your solution is still the simplest. – neverMind9 Nov 25 '18 at 10:28
  • Those two add another layer; you need to login and then run screen, have another shell, and then can communicate with your CLI. – RudiC Nov 25 '18 at 11:54
2

You can use script for this. It will record a typescript of the terminal session. By default, it will write to ./typescript. Of course, you need to do this in advance so it is not really a "screenshot".

$ script
Script started, file is typescript
$ ls asdf
ls: cannot access asdf: No such file or directory
$ exit
Script done, file is typescript

# Then check the recordings:

$ cat typescript
Script started on Thu 29 Nov 2018 02:52:04 PM CET

$ ls asdf
ls: cannot access asf: No such file or directory
$ exit

Script done on Thu 29 Nov 2018 02:52:09 PM CET
Rolf
  • 902