Record and share your Linux terminal wizardry with two simple tools

Record and share your Linux terminal wizardry with two simple tools

The Linux terminal feels secretive. Intensely private. Like the stuff you keep at the back of the closet or underneath your socks. The stuff you hope no snooping visitor will come across.

But if you’re the kind of person who likes to write about their weird Linux terminal customizations, you might someday find yourself wanting to record and share the input/output of your Linux terminal. It turns out that Linux terminal recordings ar

Why would you want (or need) to record your Linux terminal activity?

I can think of plenty of reasons:

  • You want to show off your cool one-liners.
  • You’re creating Linux/development-focused blog content and you want to show readers exactly how a certain command will run.
  • You want to document and share information with co-workers.
  • You want to record your personal procedures for posterity without typing everything out into a .txt file.
  • You’re having an issue on your Linux terminal and figure the Stack Overflow folks might understand your weird question better if you give them the full picture.
  • Because GIFs (and animated SVGs) are just plain fun!

Using asciinema to create gif recordings of your Linux terminal

Installing asciinema is super simple (GitHub). Either use sudo pip3 install asciinema or read the installation instructions for Ubuntu, Debian, and Fedora.

Once installed, you can initiate a recording with asciinema rec recording.json. When you’re done, either type in Ctrl + D or type in exit and hit Enter. You can then play the recording back using asciinema play recording.cast.

Once you’ve confirmed it looks the way you want, you can upload it to by issuing asciinema upload recording.cast. You have to authenticate yourself if you’d like your recording to stick around, but that process is super easy. The script and the website will walk you through it.

Here’s me trying one of the many cool one-liners from our One-line Wise tool!

Now that you know how to make, upload, and share recordings, let’s throw some SVG into the mix.

Converting your Linux terminal recordings to animated gifs

We’re now moving onto svg-term-cli (GitHub), which is a simple script for converting asciinema-made recordings into fully-animated SVGs. Install it with npm install -g svg-term-cli.

You have two options. You can either convert a .cast file you uploaded to, or you can pipe a .cast file directly into svg-term-cli. First, let’s convert from

$ svg-term --cast=237456 --out examples/manrandom.svg
A recording of looking at a random man page

Or, converting from a pipes.cast file I have on my comupter:

$ cat pipes.cast | svg-term --out pipes.svg
A recording of

Why go SVG?

  • SVGs can sometimes go where GIFs can’t.
  • Animated SVGs tend to have smaller file sizes than GIFs.
  • You can zoom into SVGs and get perfect vector quality.
  • You can also make your SVG recordings as large as you’d like without quality loss (or bigger file sizes).
  • SVGs play friendly with Markdown formatting.
  • SVGs are just dang cool.

Why not go SVG?

  • Most CMSs, including WordPress, don’t allow for SVG uploads. SVGs are a document, not a binary, and thus can include all sorts of nasty things, like malicious JavaScript. I ended up uploading them into the theme assets. Not the best solution.

Wrapping up

Now that you know how to record your terminal in both GIF and SVG, it’s time to get sharing! It’s awesome to see what people are up to. I mean, just checkout this raytracing animation:

Have other uses for asciinema and/or svg-term-cli? Send me and email at mailto:[email protected] and I’ll add them to the post.