IntroductionAsciinema is a lightweight and very efficient alternative to a
Scriptterminal session recorder. It allows you to record, replay and share your JSON formatted terminal session recordings. The main advantage in comparison to desktop recorders such as Recordmydesktop, Simplescreenrecorder, Vokoscreen or Kazam is that Asciinema records all standard terminal input, output and error as a plain ASCII text with ANSI escape code .
As a result, JSON format file is minuscule in size even for a longer terminal session. Furthermore, JSON format gives the user the ability to share the Asciinema JSON output file via simple file transfer, on the public website as part of embedded HTML code or share it on Asciinema.org using asciinema account. Lastly, in case that you have made some mistake during your terminal session, your recorded terminal session can be retrospectively edited using any text editor, that is if you know your way around ANSI escape code syntax.
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of
- $ - requires given linux commands to be executed as a regular non-privileged user
Standard Repository InstallationIt is very likely that asciinema is installable as part fo your distribution repository. However, if Asciinema is not available on your system or you wish to install the latest version, you can use Linuxbrew package manager to perform Asciinema installation as described below in the "Installation From Source" section.
# pacman -S asciinema
# apt install asciinema
$ sudo apt install asciinema
$ sudo dnf install asciinema
Installation From SourceThe easiest and recommended way to install the latest Asciinema version from source is by use of Linuxbrew package manager.
PrerequisitesThe following list of prerequisites fulfils dependency requirements for both, Linuxbrew and Asciinema.
# pacman -S git gcc make ruby
# apt install git gcc make ruby
$ sudo apt install git gcc make ruby
$ sudo dnf install git gcc make ruby
# yum install git gcc make ruby
Linuxbrew InstallationThe Linuxbrew package manager is a fork of the popular Homebrew package manager used on Apple's MacOS operating system. Homebrew is known for its ease of use, which is to be seen shortly, when we use Linuxbrew to install Asciinema. Run the bellow command to install Linuxbrew on your Linux distribution:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install)"Linuxbrew is now installed under your
$HOME/.linuxbrew/. What remains is to make it part of your executable
$ echo 'export PATH="$HOME/.linuxbrew/bin:$PATH"' >>~/.bash_profile $ . ~/.bash_profileTo confirm the Linuxbrew installation you can use
brewcommand to query its version:
$ brew --version Homebrew 1.1.7 Homebrew/homebrew-core (git revision 5229; last commit 2017-02-02)
Asciinema InstallationWith the Linuxbrew now installed, the installation of Asciinema should be easy as single one-liner:
$ brew install asciinemaCheck the correctnes of asciinema installation:
$ asciinema --version asciinema 1.3.0
Recording Terminal SessionAfter all that hard work with the installation, it is finally time to have some fun. Asciinema is an extremely easy to use software. In fact, the current version 1.3 has only few command line options available and one of them is
Let's start by recording a terminal session using the
recoption. The following linux command will start recording your terminal session after which you will have an option to either discard your recording or upload it on asciinema.org website for a future reference.
$ asciinema recOnce you run the above command, you will be notified that your asciinema recording session has started, and that the recording can be stopped by entering
CTRL+Dkey sequence or execution of
exitcommand. If you are on Debian/Ubuntu/Mint Linux you can try this as your first asciinema recording:
$ su Password: # apt install sl # exit $ slOnce you enter the last exit command you will be asked:
$ exit ~ Asciicast recording finished. ~ Press <Enter> to upload, <Ctrl-C> to cancel. https://asciinema.org/a/7lw94ys68gsgr1yzdtzwijxm4If you do not feel like to upload your super secret kung-fu command line skills to asciinema.org, you have an option to store Asciinema recording as a local file in JSON format. For example, the following asciinema recording will be stored as
$ asciinema rec /tmp/my_rec.jsonAnother extremely useful asciinema feature is time trimming. If you happen to be a slow writer or perhaps you are doing multitasking, the time between entering and execution of your commands can stretch greatly. Asciinema records your keystrokes real-time, meaning every pause you make will reflect on the lenght of your resulting video. Use
-woption to shorten the time between your keystrokes. For example, the following linux command trims the time between your keystrokes to 0.2 seconds:
$ asciinema rec -w 0.2
Replay Recorded Terminal SessionThere are two options to replay your recorded terminal sessions. First, play you terminal session directly from asciinema.org. That is, provided that you have previously uploaded your recording to asciinema.org and you have valid URL:
$ asciinema play https://asciinema.org/a/7lw94ys68gsgr1yzdtzwijxm4Alternatively, use your locally stored JSON file:
$ asciinema play /tmp/my_rec.jsonUse
wgetcommand to download your previously uploaded recording. Simply add
.jsonto your existing URL:
$ wget -q -O steam_locomotive.json https://asciinema.org/a/7lw94ys68gsgr1yzdtzwijxm4.json $ asciinema play steam_locomotive.json
index.htmlcode. First, download all necessary parts:
$ cd /tmp/ $ mkdir steam_locomotive $ cd steam_locomotive/ $ wget -q -O steam_locomotive.json https://asciinema.org/a/7lw94ys68gsgr1yzdtzwijxm4.json $ wget -q https://github.com/asciinema/asciinema-player/releases/download/v2.4.0/asciinema-player.css $ wget -q https://github.com/asciinema/asciinema-player/releases/download/v2.4.0/asciinema-player.jsNext, create a new
/tmp/steam_locomotive/index.htmlfile with a following content:
<html> <head> <link rel="stylesheet" type="text/css" href="./asciinema-player.css" /> </head> <body> <asciinema-player src="./steam_locomotive.json" cols="80" rows="24"></asciinema-player> <script src="./asciinema-player.js"></script> </body> </html>Once ready, open up your web browser, hit CTRL+O and open your newly created
/tmp/steam_locomotive/index.htmlfile. The result should look similar to the example video below:
ConclusionAs mentioned before, the main advantage for recording your terminal sessions with the Asciinema recorder is the minuscule output file which makes your videos extremely easy to share. The example above produced a file containing 58 472 characters, that is 58KB for 22 seconds video session. When reviewing the output JSON file, even this number is greatly inflated, mostly due to the fact that we have seen a Steam Locomotive rushing across our terminal. Normal terminal session of this length should produce a much smaller output file.
Next, time when you are about to ask a question on forums about your Linux configuration issue and having a hard time to explain how to reproduce your problem, simply run:
$ asciinema recand paste the resulting URL into your forum post.
asciinema needs a UTF-8Error message:
asciinema needs a UTF-8 native locale to run. Check the output of `locale` command.Solution:
Generate and export UTF-8 locale. For example:
$ localedef -c -f UTF-8 -i en_US en_US.UTF-8 $ export LC_ALL=en_US.UTF-8