Ttyrec, a program to record your activity in Ubuntu terminal

about ttyrec

In the next article we are going to take a look at ttyrec. This is a program that has been around for a few years, but is still capable of record the TTY output of a program in text mode along with timestamps and then play it back. This program is similar to the script command, but it also allows you to pause, slow down or speed up playback.

With ttrec we can record all the commands that we write at the terminal prompt and store them in a file. Then allows to play them with the ttyplay command. In addition we can also convert recording to animated gif with ttygif. Ttrec is a fork of the script command to record timing information with microsecond precision.

General characteristics of ttyrec

Some of the features it includes are:

  • ttyrec requires fewer parameters for recording and playback than other options to save the terminal.
  • Records in a single file.
  • You can record emacs -nw, vi, lynx or any program that runs on tty.
  • The output file contains timestamp information in addition to the terminal data.
  • We will be able overwrite or add content to the generated file.
  • Call automatically uudecode.
  • Speed ​​up / slow down reproductions.
  • Allows browse a ttyrecord recording in real time.
  • We can measure the time of recorded data.

Install ttyrec

The ttyrec program is not included by default in all Gnu / Linux distributions. To install it you just have to use apt. To install it, in a terminal (Ctrl + Alt + T) we will have to execute:

ttyrec installation

sudo apt install ttyrec

Its use is quite simple, even more than the Script command. To execute it you will have to call the program specifying the name of the output file. The format to use would be something like the following:

ttyrec < ArchivodeLog >

How to use ttyrec

The following example shows ttyrec recording the session in a file called ttylog:

ttyrec -a ttylog

It can stop recording terminal activity pressing the key combination Ctrl + D. We can also write exit.

To use this command we will have available some options such as:

  • -a →Add the output to the file or ttyrecord, instead of overwriting it.
  • -u → With this option ttyrec automatically calls uudecode and saves its output when the encoded data appears in the session. Will allow us transfer files from remote host.
  • -e command → Invoke a command when ttyrec starts.

For more information about this program, you can visit the project website o consult the man page typing in terminal (Ctrl + Alt + T):

ttyrec man pages

man ttyrec

Recorded data can be played back with the ttyplay command that is included. To play the recorded activity, you need use the ttyplay command followed by the name of the log file:

ttyplay < ArchivodeLog >

Convert recording to GIF

We will be able use TTYGIF to convert the recording to GIF. This program has the project uploaded to GitHub with instructions on its installation and use.

ttygif installation

sudo apt install imagemagick ttyrec gcc x11-apps

git clone https://github.com/icholy/ttygif.git

cd ttygif

make

sudo make install 

Creating a gif is very simple. First we started recording with:

ttyrec ejemplo

Once we are done, we can use the combination Ctrl + D In the terminal. We can also do it with the order exit, with the disadvantage that that last command will be recorded in the generated GIF.

Now for convert to gif format all you have to do is use a command like the following:

gif file creation with ttygif

ttygif ejemplo

And we already have it. Our gif will have been saved in the file tty.gif. If we get an error like: Error: WINDOWID environment variable was empty, it will be necessary to configure WINDOWID manually. This can be done by typing in the terminal (Ctrl + Alt + T):

sudo apt-get install xdotool

export WINDOWID=$(xdotool getwindowfocus)

After writing the previous commands, we can now launch the ttygif command again to start creating the gif. Creating this file may take a while.

gif created with ttygif

uninstall

To remove ttyrec from your computer, you just have to open a terminal (Ctrl + Alt + T) and write the following command:

sudo apt remove ttyrec

Programs like this are a good choice for terminal session recordings. These types of programs are a good option to share knowledge or tutorials. The ttyrec command, although it is not installed by default, is a good option for users who are not used to running a lot of commands in the terminal. This is one more of the many possibilities that exist today to record and reproduce the activity of the terminal.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.