Linux – Read what is written to /dev/tty*

consolelinuxtty

How can I read what is written to /dev/tty*(* = 0 – number of tty)?

I tried sudo tail -f /dev/tty1 on one terminal(X) and then sudo cp .emacs /dev/tty1 from another. X didn't show the the content of .emacsbut pressing Ctrl-Alt-F1 I could see the content of the .emacs.

Background.

Is this question of the same category as this?

Best Answer

On Linux, you can dump the current text that is displayed on a text mode console through the vcs devices. For example, cat /dev/vcs1 dumps the content of /dev/tty1. The vcsa devices (e.g. /dev/vcsa1) contain text attributes as well.

Every time you open /dev/vcsNUM, you get the current content of the terminal's display buffer. This isn't an interface to what is currently being printed to the terminal — there's no such interface.

For pseudo-terminals, what is currently displayed is tracked by the terminal emulator, and there is no way to dump it unless the terminal emulator provides one. For example, for a pseudo-terminal provided by ssh, the terminal content would be on the client machine.

Related Question