How To Record Everything In Terminal

Chưa phân loại
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 <LogFile>

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=<TimeFile>  <OutputFile>

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 <TimeFile> –typescript <OutputFile>

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 <Log-File>

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 <Log-File>

Since I saved the file as Lhinttyrec I execute:

$ ttyplay Lhinttyrec


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

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Deploying Apps on Kubernetes Clusters

In a previous article we deployed a Kubernetes Cluster with one master and one worker node. Kubernetes clusters are mainly...

How to Install and Get Started with QGIS 3 on Ubuntu 18.04

QGIS is an open source software package for drawing geospatial information. QGIS is a very popular and cross platform GIS...
Chưa phân loại, vps giá rẻ

VRChat for Linux

VRChat is a massive multiplayer online virtual reality platform launched in 2017 by VRChat Inc. The game was initially...
Chưa phân loại, vps giá rẻ