Terminal

How To Record Everything In Terminal

How To Record Everything In Terminal
This tutorial shows how to record everything in terminal locally to be played later both with script and ttyrec commands. While script is included in some Linux distributions and allows to manage the playing speed, ttyrec requires less parameters to record and play.

How To Record Everything In Terminal

The first option to record terminal activity on this tutorial focuses on the command Script already included in many Linux distributions by default. The easiest way to use it without  flags allows to read the log file using the cat command, to run it just execute the command specifying the output file name.

$ script

In my case I saved it as “linuxhintlog.txt” as in the example below:

$ script linuxhintlog.txt

You'll be able to see the script command started as shown in the image above, now you can type any command, then you can stop recording by typing “exit”.

At this stage you aren't able to play the session in real time, yet you can read it using the cat command:

$ cat linuxhintlog.txt

In order to play the session rather than reading it you need to add

the -timing option specifying the time file name additionally to the output file name:

$ script --timing= 

In my case I saved the time file as TIMEFILE and the output file as LHoutput.txt as in the following example:

$ script --timing=TIMEFILE LHoutput.txt

To play the recorded session the command is scriptreplay followed by the -timing flag, time file name, -typescript flag and output file name as in the example below:

$ scriptreplay --timing --typescript

In the following example the time file is TIMEFILE and LHoutput.txt the output file:

$ scriptreplay --timing TIMEFILE --typescript LHoutput.txt

You may want to speed up or slow the playing speed, this can be achieved by using the -m (-maxdelay) and -d (-divisor) flags. With the -m option you can define the timing in seconds to play each activity, while the -d flag allows to divide it.

The following example shows how to play allowing a maximum of a second delay per command:

$ scriptreplay -m 1 --timing TIMEFILE --typescript LHoutput.txt

The next examples divides the real timing for the factor you specify, in this case I will double the speed by specifying the factor “2”.

$ scriptreplay -d 2 --timing TIMEFILE --typescript LHoutput.txt

Of course to notice the difference you must try it by yourself,

How to Record Everything in Terminal using TTYREC

Another method to record everything in terminal is the command ttyrec, but ttyrec program isn't included by default on all Linux distributions, at least not in Debian. To install it simply run:

$ apt install ttyrec

It's use is pretty easy, even more than the Script command explained before. To run it just call the program specifying the output file name:

$ ttyrec 

The following example shows ttyrec recording the session on a file called Lhinttyrec:

$ ttyrec Lhinttyrec

As you can see you can exit the recording session by using the “exit” command like with the script command.

To play the recorded activity you need to call the command ttyplay followed by the log file name:

$ ttyplay

Since I saved the file as Lhinttyrec I execute:

$ ttyplay Lhinttyrec

Conclusion:

Recording terminal sessions are a good option to share knowledge, tutorial or even take tests when replying or output speed are important.The script command is the best option if you need to manipulate the playing speed, it also comes by default on Linux distributions like Debian or Ubuntu.

The Ttyrec command, despite does not come installed by default, is a good option for users who aren't used to run commands on the terminal due the lack of flags, recording and playing requires less commands than the script program. At the end both options are pretty simple to use to record and play terminal activity. Both commands have friendly and easy man pages for users applying these commands for the first time.

I hope you found this brief tutorial on recording terminal sessions useful, thank you for reading it and keep following LinuxHint for additional updates and tips on Linux and Networking.

Related articles

  • 5 Best Ubuntu Screen Recorders for Every User
  • Record Screen with Kazam on Ubuntu
  • Update Ubuntu Terminal Color Scheme
  • 60 FPS Screen Recording Apps for Linux
  • Top GIF Recorders For Linux
  • 7 Best Terminal Alternatives for Ubuntu
  • All about the debian package managers: dpkg, apt and aptitude explained
Gry Open Source Ports of Commercial Game Engines
Open Source Ports of Commercial Game Engines
Free, open source and cross-platform game engine recreations can be used to play old as well as some of the fairly recent game titles. This article wi...
Gry Najlepsze gry wiersza poleceń dla systemu Linux
Najlepsze gry wiersza poleceń dla systemu Linux
Wiersz poleceń jest nie tylko twoim największym sprzymierzeńcem podczas korzystania z Linuksa - może być również źródłem rozrywki, ponieważ możesz go ...
Gry Najlepsze aplikacje do mapowania gamepada dla systemu Linux
Najlepsze aplikacje do mapowania gamepada dla systemu Linux
Jeśli lubisz grać w gry na Linuksie za pomocą gamepada zamiast typowego systemu wprowadzania klawiatury i myszy, jest kilka przydatnych aplikacji dla ...