On tty2, how do I take a text screenshot of the command line?
3 Answers
Did you consider the screendump command?
- 
        3"Just sayingcat /dev/vcsNhas a similar effect". Then why not just usecat /dev/vcsN?Weijun Zhou– Weijun Zhou2018-11-24 16:45:16 +00:00Commented Nov 24, 2018 at 16:45
- 
        5
- 
        Nice. Is there a way to get it to do colour as well? (screendumpreads from/dev/vcsadevices which does have colour information, but it seems to be stripped from the output.) Btw. I like to combine it with thewatchcommand to see live output likewatch -n0.1 screendump.kasperd– kasperd2018-11-25 13:25:02 +00:00Commented Nov 25, 2018 at 13:25
- 
        @WeijunZhou/dev/vcsdevices don't contain information about the size of the screen, socat /dev/vcsNonly works if your terminal window has the same number of characters across as the VC you are capturing.kasperd– kasperd2018-11-25 13:26:35 +00:00Commented Nov 25, 2018 at 13:26
If you can use tmux or screen, they have the ability to save the scrollback buffer to a file.
- Write all tmux scrollback to a file
- Copying GNU screen scrollback buffer to file (extended hardcopy)?
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.
- 
        Because of that, I marked this one as accepted. But @RudiC Don't take it personally. Your solution is still the simplest.neverMind9– neverMind92018-11-25 10:28:39 +00:00Commented Nov 25, 2018 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– RudiC2018-11-25 11:54:51 +00:00Commented Nov 25, 2018 at 11:54
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