Asciinema – Record Terminal Sessions And Share Them On The Web

Asciinema - Record Terminal sessions

I already know about recording the Terminal activities using “script” command in Unix-like systems. Today, I found out yet another similar utility called “asciinema” that can 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. Also, we will 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, run the following command to install asciinema.

sudo pacman -S asciinema

On Debian:

sudo apt-get install asciinema

Fedora:

sudo dnf install asciinema

openSUSE:

sudo zypper in asciinema

Ubuntu, Linux Mint and other Ubuntu flavours:

sudo apt-add-repository ppa:zanchey/asciinema
sudo apt-get update
sudo apt-get install 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 combile 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

The usage is trivial.

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

$ asciinema 
usage: __main__.py [-h] [--version] {rec,play,upload,auth} ...

Record and share your terminal sessions, the right way.

positional arguments:
 {rec,play,upload,auth}
 rec Record terminal session
 play Replay 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.json
 Record terminal and upload it to asciinema.org, specifying title:
 asciinema rec -t "My git tutorial"
 Record terminal to local file, "trimming" longer pauses to max 2.5 sec:
 asciinema rec -w 2.5 demo.json
 Replay terminal recording from local file:
 asciinema play demo.json
 Replay terminal recording hosted on asciinema.org:
 asciinema play https://asciinema.org/a/difqlgx86ym6emrmd8u62yqu8

For help on a specific command run:
 asciinema <command> -h

Record terminal sessions

Now, 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, your Terminal activities is being recorded and saved in the file called “test” in the current working directory.

Let us type some random commands.

uname -a
echo "Welcome to OSTechNix"
ls -l
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.

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.

Also, you can share it on social networks or embed it on other websites or on your own blog.

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

Also, you can 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 them online anymore.

In my opinion, Acsiinema is simple, yet very useful to me. The “script” command helped me to record my Terminal session and view the recorded session later. Asciinema utility went one step ahead and allowed me to share my terminal session with other users. Give it a try, you won’t be disappointed.

And, that’s all for now. More good stuffs to come. Stay tuned!

Cheers!

Resource:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...