How to Record Your Terminal Actions on Linux

Summary: Recording a terminal operation can be an easy-to-understand way to help others learn Linux, demonstrate a series of correct command-line operations, and share knowledge. Regardless of the purpose, copying and pasting text from the terminal requires many repetitions, and the process of recording video is cumbersome and sometimes impossible.

Recording a terminal operation can be an easy-to-understand way to help others learn Linux, demonstrate a series of correct command-line operations, and share knowledge. Regardless of the purpose, copying and pasting text from the terminal requires many repetitions, and the process of recording video is cumbersome and sometimes impossible. In this article, we will take a brief look at how to record and share terminal sessions in gif format.

Pre-requirements
If you just want to be able to record your terminal session and play it back in the terminal or share it with others, then all you need is a piece of software called: ttyrec. Ubuntu users can install it by running this line of code:

sudo apt-get install ttyrec
If you want to convert the resulting video into a gif file that can be shared with those who don't use a terminal, you can post it on a website, or you can Just want to make a gif easy to use and don't want to write commands. Then you need to install two additional packages. The first is imagemagick, you can install it with the following command:

sudo apt-get install imagemagick
The second package is: tty2gif.py, visit its project website to download. This package needs to install the following dependencies:

sudo apt-get install python-opster
recording
To start recording terminal operations, all you need is to type ttyprec and hit enter. This command will run a real-time logging tool in the background. We can stop by typing exit or ctrl+d. ttyrec will create a ttyrecord file in the home directory by default.




Playback Playing
back this file is very simple. You just need to open a terminal and use the ttyplay command to open the ttyrecord file. (In this example, we use ttyrecord as the file name, of course, you can change it to your own file name)


Then you can start playing the file. This video records all operations, including your deletion, modification. It looks like a terminal with self-awareness, but the process of executing this command is not just for the system to see, but for better presentation to people.

Note that playing this recording is completely controllable, you can click + or - to speed up and slow down, or 0 and 1 to pause and resume playback.

Export to GIF
For convenience, we usually convert video recordings to gif format, and this is very easy to do. The following is the method:

Copy the tty2gif.py file downloaded earlier to the same directory as the ttyprecord file (or the video file you named), then open the terminal in this directory and enter the command:

python tty2gif.py typing ttyrecord
if it appears error, check if you have the python-opster package installed. If there are still errors, use the following commands to troubleshoot.

sudo apt-get install xdotool
export WINDOWID=$(xdotool getwindowfocus)
Then repeat the command python tty2gif.py and you will see some more gif files in the ttyrecord directory.


The next step is to integrate all the gif files and package them into one gif file. We do this by using the imagemagick tool. Type the following command:

convert -delay 25 -loop 0 *.gif example.gif

You can use any file name, I used example.gif. Also, you can change this delay and loop time. Enjoy.

The original release time is: 2016-07-14

This article is from the Yunqi community partner "Linux China"


using the Yunqi community APP, comfortable~

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326305460&siteId=291194637