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

Install Swift 3.0.2 iOS Programing Language on Ubuntu

Swift 3.0.2 most recent release, is an interactive, fun general-purpose programming language built using a modern approach...

Inkscape, Krita Graphics Editors now available on Windows Store

The two most popular open-source graphics editing applications Inkscape, Krita are now available for download on the Windows...

Install Docker on Raspberry Pi

Docker is a containerization system for Linux. It is used to run lightweight Linux containers on top of another Linux host...
Bài Viết

Bài Viết Mới Cập Nhật

mua Proxy riêng ở đâu, và nó đem lại lợi ích gì cho người sử dụng

Hướng dẫn sử dụng Proxy Helper Fakeip khi thuê proxy


Mua Proxy Nuôi Zalo Giá Rẻ Tại