How To Record Your Terminal Window On Linux

In this blog post, we will discuss that very thing, from features to how to install, record, and playback the recordings, and more.

On this page
  1. Features
  2. How To Install
  3. Recording
  4. Playback
  5. Bonus: Recording All Your SSH Sessions
  6. Conclusion

Although you can use traditional screen recording software to capture your screen, there are better solutions. I’m introducing Asciinema, a tool specifically made to record terminal sessions. What makes this tool better, you ask? In this blog post, we will discuss that very thing, from features to how to install, record, and playback the recordings, and more.

#Features

Below is a list of some of the most important features.

  • smaller files than traditional screen recording software
  • copy and paste from recordings
  • Is Open Source
  • Cross-platform Support
  • Customization during Playback
  • Embedding and Sharing

#How To Install

There are two main ways to install Asciinema one is to search your systems package manager for Asciinema and the other is to install the Python package directly.

Apt-based distros such as Debian or Ubuntu:

Code
apt install asciinema

DNF-based distributions such as AlmaLinux, CentOS, Fedora, RHEL, and more:

Code
dnf install asciinema

For Arch Linux and Arch-based Distros:

Code
pacman -S asciinema

Installing The Python Package Directly

If your distro doesn’t have a direct package for asciinema, you can use a Python package manager like pip or pipx to install the package.

Using pip:

Code
python3 -m pip install asciinema

Using pipx:

Code
pipx install asciinema

#Recording

To start recording a terminal session you first need to decide if you want to record the file locally or upload it to asciinema.org.

To record locally make sure to specially a filename

Code
asciinema rec filename.cast

If you don’t have anything personal you plan to record and are fine uploading it publicly you don’t have to specify the filename.

#Playback

Playback can be customized, but before we look at the options let’s look at basic playback.

Code
asciinema play [filename or URL of cast file]

This will play the recording as it was recorded (if the recording was 5min so is playback).

#Bonus: Recording All Your SSH Sessions

Do you need to record all your ssh sessions? The function below catches any commands starting with SSH then runs them through asciinema and records them to a folder called asciinema in your home directory.

Code
function ssh {

 ssh=$(whereis -b ssh | cut -d' ' -f2)
 SESSION_NAME="ssh-$(date +%Y%m%d-%H%M%S)"

 # Create asciinema recording (for users not using sshrc)
 asciinema rec -y "$HOME/asciinema/$SESSION_NAME.cast" --command "$ssh $@"

}

#Conclusion

Asciinema is a tool designed specifically recording terminal sessions, in this blog post we touched on features compared to traditional screen recording software. Then moved one to how to install, record, and playback the recordings. As I only touched the surface if you looking for other features or more intonation please check out asciinema docs site as it goes into much more detail than we can in a single blog post.

Illustrated avatar of CJ Saathoff
Written by

CJ Saathoff

CJ Saathoff writes for the NameHero blog.

More from CJ →