Home Command line utilities How To Record Terminal Sessions As SVG Animations In Linux

How To Record Terminal Sessions As SVG Animations In Linux

By sk
Published: Last Updated on 1.4K views

Recording Terminal sessions may help in several cases. You can use those recording sessions to document everything that you did in Terminal and save them for future reference. You can use them to demonstrate different Linux commands and its use cases to your juniors, students and anyone who are willing to Learn Linux. Luckily, we have many tools to record Terminal sessions in Unix-like operating systems. We already have covered some of the tools/commands which helps you to record the Terminal sessions in the past. You can go through them in the links given below.

Today, we are going to see yet another tool to record the Terminal activities. Say hello to "Termtosvg". As the name implies, Termtosvg records your Terminal sessions as standalone SVG animations. It is a simple command line utility written in Python programming language. It generates lightweight and clean looking animations embeddable on a project page. It supports custom color themes, terminal UI and animation controls via SVG templates. It is also compatible with asciinema recording format. Termtosvg supports GNU/Linux, Mac OS and BSD OSes.

Installing Termtosvg

Termtosvg can be installed using PIP, a python package manager to install applications written using Python language. If you haven't installed PIP already, refer the following guide.

After installing PIP, run the following command to install Termtosvg tool:

$ pip3 install --user termtosvg

And, install the following prerequisites to render the Terminal screen.

$ pip3 install pyte python-xlib svgwrite

Done. Let us go ahead and generate Terminal sessions in SVG format.

Record Terminal Sessions As SVG Animations In Linux

Recording Terminal sessions using Termtosvg is very simple. Just open your Terminal window and run the following command to start recording it.

$ termtosvg

Note: If you termtosvg command is not available, restart your system once.

You will see the following output after running 'termtosvg' command:

Recording started, enter "exit" command or Control-D to end

You will now be in a sub-shell where you can execute the Linux commands as usual. Everything you do in the Terminal will be recorded.

Let me run a random commands.

$ mkdir mydirectory
$ cd mydirectory/
$ touch file.txt
$ cd ..
$ uname -a

Once you're done, press CTRL+D or type exit to stop recording. The resulting recording will be saved in /tmp folder with a unique name.

Termtosvg in action

You can then open the SVG file in any web browser of your choice from Terminal like below.

$ firefox /tmp/termtosvg_ddkehjpu.svg

You can also directly open the SVG file from browser (File -> <path-to-svg>).

Here is the output of the above recording in my Firefox browser.

Termtosvg in browser

Playing SVG file in browser

Here is some more examples on how to use Termtosvg to record Terminal sessions.

Like I mentioned already, Termtosvg will record a terminal session and save it as an SVG animation file in /tmp directory by default.

However, you can generate an SVG animation with a custom name, for example animation.svg, and save it in a custom location, for example /home/sk/ostechnix/.

$ termtosvg /home/sk/ostechnix/animation.svg

Record a terminal session and render it using a specific template:

$ termtosvg -t ~/templates/my_template.svg

Record a terminal session with a specific screen geometry:

$ termtosvg -g 80x24 animation.svg

Record a terminal session in asciicast v2 format:

$ termtosvg record recording.cast

Render an SVG animation from a recording in asciicast format:

$ termtosvg render recording.cast animation.svg

For more details, refer Termtosvg manual.

Resources:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

1 comment

Alireza ghahrood September 24, 2018 - 12:53 pm

So nice : terminal record – linux

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More