How to record Terminal sessions as ASCII video in Ubuntu

Using asciinema, you can record and share Terminal sessions where a user will be able to select text from the video.

There are several times that you might need to record a video of a sequence of commands in terminal. Let it be for a tutorial or for teaching seasons or just for your own reference.

Recording a video does not allow you to copy from it, so you need to provide some transcript of the video if you want your viewers to be able to copy your commands for further use.

Asciinema is a nice tool to be able to share a video of your console/terminal as an ASCII video. From this ASCII video, you will see exactly the same that happened on the console while recording and you can select all texts from the video. Here is a sample video, courtesy of asciinema.

Exciting isn’t it? In this Terminal Tuts, we will guide you on how to install asciinema and its basic usage. We are using Ubuntu in this tutorial but this guide should work on Linux Mint, elementary OS and other Ubuntu derivatives.

Installing asciinema using packages

We will make the basic installation in Ubuntu using packages, but basically, the installation procedure is easy on any system, first of all, as usual, it’s better to update apt repositories before installing:

sudo apt update

Once repositories are updated, we can install the package:

sudo apt install asciinema

and that’s all, we have asciinema installed.

Installing asciinema using pip3

Pip is a package manager for Python. pip3 also is the same but when using python3, it allows to install and manage packages from Python Package Index (Pypi). We can use it to install software packages built with Python as asciinema:

If we have not pip3 installed, we first need to install python3-pip from repositories:

sudo apt update && sudo apt install python3-pip

After we have pip installed, we can just do:

sudo pip3 install asciinema

Asciinema Basic Usage

There are two ways of using asciinema, the first one is using asciinema.org service, this way, you record to asciinema cloud and you can see your recording on your account or use the embedded javascript player to replay your sessions on your webpage.

In this case, you can just record a session in your console typing:

asciinema rec

From this point, all our commands will be recorded while we just continue working on the terminal, once we have finished, we can just type:

exit

When the session is over, we will be asked if we want to upload the session to asciinema.org, if we choose yes, we will be given a hash to identify our recording.

We can also save our cast to a local file just adding a file name after rec command:

asciinema rec filename.cast

Making a local cast recording allows us to playback the file just changing the command from rec to play:

asciinema play filename.cast

We can also control the play speed with flag -s, for example, double speed:

asciinema play -s 2 filename.cast

Or limit the idle time to a given value with -i:

asciinema play -I 3 filename.cast

This will bypass any idle time above 3. Asciinema can also show all the texts as if you had recorded with ”display”:

asciinema cat filename.cast

You can also upload a local file to your desired server (defaults to asciinema.org):

asciinema upload filename.cast

We will further see in other articles on how to host your own asciinema server to serve your own casts over the web if you are not comfortable sharing them on asciinema.org.

Asciinema Advanced Options and Editing

At this point you should have a good idea about what asciinema can do for you, but there is more in the pot: asciinema can reduce death times, all the time marks will be kept but video will be played on a more fluent way. This parameter, amongst other options, can be configured by default on config file created at $HOME/.config/asciinema/config the most useful ones are:

  • command .- Used to choose the default shell command that will be opened by asciinema when the record starts, defaults to bash
  • idle_time_limit.- It can be used both on rec and play in rec config means the time from which you will not be recording when idle on the console and in play mode means the time from which you will be skipping output when idling, defaults to off
  • speed.- default playback speed (same as -s), it is a positive fraction (0.5 for 50% speed, 10 for 1000% speed), defaults to 1

You can also download a GO program (asciinema-edit) that will allow you to split content or remove idles in an already recorded cast.

Wrap Up

Asciinema is a really useful tool to record tutorials and console sessions for tests or presentations (or just self-reference), it can be easily installed on a Linux system, both as system packages or as python packages and with a simple command interface will allow you to record, light-weight ASCII casts of your console sessions. In further articles, we will see how to host your own server and embed casts or how to convert them into gifs for sharing.

Divya Kiran Kumar
I'm the Editor of FOSS Linux. I worked as a Software Engineer before taking up blogging as my full-time job. I enjoy using Linux, and can't imagine anything else for my PC. Apart from writing for FOSS Linux, I enjoy reading non-fictional books. Sapiens was my favorite last read. I hope you enjoy reading and using this blog to enhance your Linux experience! Have a great day ahead!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,276FansLike
386FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

MUST READ

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

5 Best Notepad++ Alternatives for Linux

Notepad++ has been the de facto standard for source code editors for nearly 16 years, almost since its creation in 2003.  For Windows users, that is.  For years, Linux users had no source code editor that compared to Notepad++ with all its bells and whistles, such as code folding, scripting, markup languages, syntax highlighting, auto-completion for programming (limited).

The 6 Best Download Managers for Fedora

It is a well-known fact that using download managers can help improve download speeds as compared to web browsers. Apart from the inbuilt download manager wget on Fedora, just as on any distribution that is based on GNU/Linux package, there are more options to explore.

Installing an updatable Manjaro Linux on a USB Flash Drive

In this tutorial, we will show step by step how to install a Manjaro on a USB flash. For those new to this distro, it is a light-weight distro that is based on Arch Linux. Arch Linux is known for its simplistic approach and is typically made for Linux pros, but Manjaro bridges the gap between user-friendliness and rock-solid performance.

5 Things to do when your Linux system GUI freezes

All operating systems freeze at some point and, Linux distributions are no exceptions. In this post, we are going to look at five methods you can apply to your frozen system before thinking of plugging out the power cable or holding down the power button to power off the PC.