How to save the contents of unlogged console screen to a file?

TTYs use "virtual console memory" devices to buffer their screen content. You can read more about them in man vcs but this will let you get what is on the screen at the current moment.

In practise these are just numbered files in /dev/ that line up with the TTY number. Here's an example I did with TTY2:

$ sudo fold -w$(stty -F /dev/tty2 size | awk '{print $2}') /dev/vcs2

Ubuntu 14.04 LTS bert tty2                                                      

bert login: oli                                                                 
Password:                                                                       
oli@bert:~$ cd test                                                             
oli@bert:~/test$ ls                                                             
Madonna - 10 - Bedtime Story.mp3  output_MP3WRAP.mp3                            
Madonna - 11 - Take A Bow.mp3                                                   
oli@bert:~/test$                                       

The fold -w$(...) there is because the buffered output doesn't appear to have the control characters or newlines I would expect. This simply adds \n at the end of every line.

As TuKsn points out in the comments, you don't have to mess around with all this, you can achieve exactly the same with:

sudo screendump 2

You can stick > tty.log on the end of either command to write the output to a file called tty.log in the current directory:

sudo screendump 2 > tty.log

Again, this will only get you what is on the screen. Even if you increase the scrollback buffer in TTYs, this isn't stored in accessible memory. You can alter that but that involves recompiling the kernel.

That would involve rebooting and losing the current screen so if you can do that there are much easier options for logging future IO, like screen or tmux or just script.


Probably you can use a program named screen. It saves all output of Terminal into a file. Have a look at this Ubuntu Forums thread http://ubuntuforums.org/showthread.php?t=1379903. CMIIW.