How to print contents of virtual console terminal

Sometimes it a good idea to check or just store contents of virtual console terminal (/dev/vcs[1-63] device).

To print its contents execute command:

$ sudo cat /dev/vcs2 | fold --width 80 | \
sed -e 's/ *$//g' | sed -e '/^$/N;/\n$/d' | sed -e '${G}'
CentOS release 5.7 (Final)
Kernel 2.6.18-274.7.1.el5 on an x86_64

home login:

Depending on console dimensions width parameter needs to be adjusted.

$ sudo cat /dev/vcs4 | fold --width 170 | \
sed -e 's/ *$//g' | sed -e '/^$/N;/\n$/d' | sed -e '${G}'
Ubuntu 11.10 notebook tty4

notebook login: milosz
Password:
Login timed out after 60 seconds.

Ubuntu 11.10 notebook tty4

notebook login:

If you don't care about empty lines at the end then use shorter version:

$ sudo cat /dev/vcs5 | fold --width 170 |  sed -e '${G}'
                                                                                                                                                        
milosz@notebook:~/VirtualBox VMs/Ubuntu$ file *                                                                                                                     
Logs:             directory                                                                                                                                               
Ubuntu.vbox:      XML  document text                                                                                                                                      
Ubuntu.vbox-prev: XML  document text                                                                                                                                      
Ubuntu.vdi:       data                                                                                                                                                    
milosz@notebook:~/VirtualBox VMs/Ubuntu$ ls -1 /                                                                                                                    
bin                                                                                                                                                                       
boot                                                                                                                                                                      
cdrom                                                                                                                                                                     
dev                                                                                                                                                                       
etc                                                                                                                                                                       
home                                                                                                                                                                      
initrd.img                                                                                                                                                                
initrd.img.old                                                                                                                                                            
lib                                                                                                                                                                       
lib32                                                                                                                                                                     
lib64                                                                                                                                                                     
lost+found                                                                                                                                                                
media                                                                                                                                                                     
mnt                                                                                                                                                                       
opt                                                                                                                                                                       
proc                                                                                                                                                                      
root                                                                                                                                                                      
run                                                                                                                                                                       
sbin                                                                                                                                                                      
selinux                                                                                                                                                                   
srv                                                                                                                                                                       
sys                                                                                                                                                                       
tmp                                                                                                                                                                       
usr                                                                                                                                                                       
var                                                                                                                                                                       
vmlinuz                                                                                                                                                                   
vmlinuz.old                                                                                                                                                               
milosz@notebook:~/VirtualBox VMs/Ubuntu$ pwd                                                                                                                        
/home/milosz/VirtualBox VMs/Ubuntu                                                                                                                                        
milosz@notebook:~/VirtualBox VMs/Ubuntu$                       




[...]
Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.

Gdansk, Poland https://sleeplessbeastie.eu