I already know about recording the Terminal activities using "script" command in Unix-like systems. Today, I found out yet another similar utility named "asciinema" which is used to record Terminal sessions. Forget about the heavy screen-recording tools and/or apps. Asciinema is a fast, light-weight and open source Terminal recording tool. Unlike "script" command, Asciinema not just records our Terminal activities, but also helps us to share them on the web if necessary. You can share the recordings by copying its URL and sending it to a friend or posting it on a social network. It supports Linux, Mac OS X and *BSD.

Asciinema tool could be useful in the following situations:

The online trainers can record and share the Terminal session when teaching Linux commands to the students.

The students can share their Terminal activities to their online tutors when they have been given a command-line assignment.

The junior admins can record and share their Terminal activities to the remote technical support or subject matter experts when looking for help.

Technical writers or bloggers can record the terminal activities and use them while writing a book or blog post.

The possibilities are endless. Whatever it is, when it comes it to record a terminal session, Asciinema comes in handy! In this guide, we will be discussing how to install asciinema in different Linux distros and how to record your Terminal sessions using it. We will also see how to share the recorded terminal sessions on the web.

Install Asciinema

The good thing is the developers have packaged asciinema for almost all Linux distributions, and it's available in the official repositories of many Linux distros.

On Arch Linux and derivatives like Antergos, Manjaro Linux, enable [Community] repository and run the following command to install asciinema.

$ sudo pacman -S asciinema

On Debian, Ubuntu, Linux Mint:

$ sudo apt install asciinema

On Ubuntu versions, you need to enable Universe repository to install asciinema.

$ sudo add-apt-repository universe

There is also a official PPA is available for Ubuntu and its derivatives.

$ sudo apt-add-repository ppa:zanchey/asciinema $ sudo apt-get update $ sudo apt-get install asciinema

On CentOS, RHEL:

$ sudo yum install epel-release

$ sudo yum install asciinema

Fedora:

$ sudo dnf install asciinema

openSUSE:

$ sudo zypper in asciinema

Install Asciinema as snap

Asciinema also available as snap package. You can install Snap on Arch Linux and Fedora as described here.

$ sudo snap install asciinema --classic

Install Asciinema using pip

$ sudo pip3 install asciinema

Your system should have pip3 installed before installing asciinema.

Install Asciinema from source

If none of the above methods works, you can manually compile and install it from source as shown below.

Your system should have Python 3 installed to compile Asciinema from source.

$ git clone https://github.com/asciinema/asciinema.git $ cd asciinema $ sudo python3 -m asciinema --version

To install asciinema on Unix and other operating systems, refer the asciinema installation page.

Record Terminal Sessions using Asciinema

When you run "asciinema" without any argument, it will display the help section.

$ asciinema

usage: asciinema [-h] [--version] {rec,play,cat,upload,auth} ... Record and share your terminal sessions, the right way. positional arguments: {rec,play,cat,upload,auth} rec Record terminal session play Replay terminal session cat Print full output of terminal session upload Upload locally saved terminal session to asciinema.org auth Manage recordings on asciinema.org account optional arguments: -h, --help show this help message and exit --version show program's version number and exit example usage: Record terminal and upload it to asciinema.org: asciinema rec Record terminal to local file: asciinema rec demo.cast Record terminal and upload it to asciinema.org, specifying title: asciinema rec -t "My git tutorial" Record terminal to local file, limiting idle time to max 2.5 sec: asciinema rec -i 2.5 demo.cast Replay terminal recording from local file: asciinema play demo.cast Replay terminal recording hosted on asciinema.org: asciinema play https://asciinema.org/a/difqlgx86ym6emrmd8u62yqu8 Print full output of recorded session: asciinema cat demo.cast For help on a specific command run: asciinema <command> -h

Record terminal sessions

Let us record a terminal session. To do so, run:

$ asciinema rec test

Once you run the above command, you will see the following output.

~ Asciicast recording started. ~ Hit Ctrl-D or type "exit" to finish.

Now, Asciinema will start to record the Terminal activities and save them in a file called "test" in the current working directory.

Let me type some random commands.

$ echo "Welcome to OSTechNix"

$ uname -a

$ pwd

$ touch ostechnix.txt

$ df -h

That's enough. To finish the recording, press "CTRL+D" or type "exit".

When the recording is ended, you will see the following message.

~ Asciicast recording finished.

Playing the record session

You can play the recorded Terminal session with command:

$ asciinema play test

Replace "test" with your filename.

Here is Asciinema in action.

Uploading the record session to asciinema.org wite

If you don't specify filename for the recording, you will asked to upload the resulting recording to asciinema.org website, so you can share it to your friends or social media or add it to your own blog/website.

Here is the sample output when you don't specify the file name.

~ Asciicast recording finished. ~ Press <Enter> to upload, <Ctrl-C> to cancel.

Press ENTER key to upload the recording to asciinema site. You will get an unique web URL like below after few seconds.

https://asciinema.org/a/Emsah6mnIctFdw9m3BnEdBxer

Just share it to your colleague or friend or whoever wants to view your Terminal session in their web browser. Or, you can view it on your own browser itself. Once your friend entered the above URL in their browser's address bar, they can be able to see your recording.

As stated earlier, you can even share the recordings on social networks or embed them on other websites or on your own blog.

To share the recording session, just click share button on the bottom right corner.

You can also download it if you want. To do so, just click the Download button in the bottom.

All your recording will be kept as private. So, they will not listed on any search engines or other websites. They will be only visible to someone you give the URL.

Delete recordings

To delete the recorded Terminal session, click on the Gear button next to "Download" button in the bottom, and hit "Delete" option.

Manage your recordings on asciinema.org site

You can manage your uploaded sessions on asciinena.org site. To do so, you need to authenticate to the site by running the following command on the Terminal:

$ asciinema auth

You will be given an unique URL like below.

https://asciinema.org/connect/24f95ad3-e046-3fd9-b2d7-5f245b5ba42f

Open the above URL in a browser to register your API token and assign any recorded asciicasts to your profile.

Enter your details and click Save to create your profile.

Now, you can edit, set title/description to your uploaded recordings and also you can delete if you don't want to keep them in online anymore.

Suggested read:

Conclusion

Acsiinema is simple, yet very useful to me. The "script" command helped me to record my Terminal session and view the recorded session later. However, Asciinema utility allowed me to share my recorded terminal sessions with other users. Give it a try, you won't be disappointed.

Resources: