Site icon UnixArena

How to Create Animated GIFs from Linux Terminal Output: A Step-by-Step Guide

gif linux

gif linux

Capturing and sharing terminal sessions has never been easier with Asciinema, a powerful tool for recording command-line interactions. In this blog post, we’ll explore how to harness the capabilities of Asciinema to create captivating GIF animations from your terminal sessions. Whether you’re documenting a tutorial, showcasing your command-line prowess, or simply adding visual appeal to your technical content, generating GIFs with Asciinema opens up a world of possibilities. Join us as we dive into the step-by-step process of recording terminal sessions, converting them into animated GIFs, and unleashing the full potential of Asciinema for your projects.

Prerequisites:

  • RedHat Linux / Cent OS/Ubuntu
  • Internet connectivity
  • Docker software on Linux VM

1. Login to the Linux machine: Login to the Linux machine in which you would like to capture the command outputs in gif animated format.

2. Install Asciinema: If you haven’t already, install Asciinema on your Linux system by following the instructions on the official website.

[root@centos9 ~]# dnf install asciinema
Last metadata expiration check: 2:14:51 ago on Wed 01 May 2024 04:39:52 AM UTC.
Package asciinema-2.2.0-4.el9.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@centos9 ~]#

3. Record Your Terminal Session: Open a terminal window and start recording your terminal session using the “asciinema rec” command. This will start recording your terminal session and save it to a file named uademo1.cast.

[root@centos9 ~]# asciinema rec uademo1.cast
asciinema: recording asciicast to uademo1.cast
asciinema: press or type "exit" when you're done
[root@centos9 ~]#

4. Perform Actions: Perform the actions you want to record in the terminal. This could be running commands, navigating directories, or executing scripts.

5. Stop Recording: Once you’re done recording, press Ctrl + D to stop the recording session.

6. Convert to GIF: To convert the recorded session to a GIF, you can use the asciicast2gif tool provided by Asciinema. Run the following command:

[root@centos9 ~]# docker run --rm -v $PWD:/data asciinema2/asciicast2gif -t asciinema uademo1.cast uademo1.gif
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
==> Loading uademo1.cast...
==> Spawning PhantomJS renderer...
==> Generating frame screenshots...
==> Combining 28 screenshots into GIF file...
==> Done.
[root@centos9 ~]#

Replace uademo1.cast with the filename of your recorded session and uademo1.gif with the desired filename for the GIF output.

Colour theme: asciinema, tango, solarized-dark, solarized-light, monokai (default: asciinema). You can choose any one of the themes using the “-t” option.

7. View the GIF: Once the conversion is complete, you can view the generated GIF using any image viewer or web browser. It will be available in your current directory

Conclusion:

By following these steps, you can easily record your terminal sessions using Asciinema and convert them into GIFs for sharing or embedding in your blog posts or documentation.

Example:

Convert asciinema cast to gif
Exit mobile version