Asciinema:在云端记录并分享你的终端会话
创始人
2024-03-02 01:54:30
0

这个众所周知的话题我们早已经写过了足够多的文章。即使这样,我们今天也要去讨论相同的话题。

其他的工具都是在本地运行的,但是 Asciinema 可以以相同的方式在本地和 Web 端运行。我的意思是我们可以在 Web 上分享这个录像。

默认情况下,每个人都更愿意使用 history 命令来回看、调用之前在终端内输入的命令。不过,不行的是,这个命令只展示了我们运行的命令却没有展示这些命令上次运行时的输出。

在 Linux 下有很多的组件来记录终端会话活动。在过去,我们也写了一些组件,不过今天我们依然要讨论这同一类心的工具。

如果你想要使用其他工具来记录你的 Linux 终端会话活动,你可以试试 Script 命令Terminalizer 工具Asciinema 工具

不过如果你想要找一个 GIF 录制工具,可以试试 GifineKgifPeek

什么是 Asciinema

asciinema 是一个自由开源的用于录制终端会话并将它们分享到网络上的解决方案。

当你在你的终端内运行 asciinema rec 来启动录像时,你输入命令的时候,终端内的所有输出都会被抓取。

当抓取停止时(通过按下 Ctrl-D 或输出 exit),抓取的输出将会被上传到 asciinema.org 的网站,并为后续的回放做准备。

Asciinema 项目由多个不同的完整的部分组成,比如 asciinema 命令行工具、asciinema.org API 和 JavaScript 播放器。

Asciinema 的灵感来自于 scriptscriptreplay 命令。

如何在 Linux 上安装 Asciinema

Asciinema 由 Python 写就,在 Linux 上,推荐使用 pip 安装的方法来安装。

确保你已经在你的系统里安装了 python-pip 包。如果没有,使用下述命令来安装它。

对于 Debian/Ubuntu 用户,使用 Apt 命令Apt-Get 命令 来安装 pip 包。

$ sudo apt install python-pip

对于 Archlinux 用户,使用 Pacman 命令 来安装 pip 包。

$ sudo pacman -S python-pip

对于 Fedora 用户,使用 DNF 命令 来安装 pip 包。

$ sudo dnf install python-pip

对于 CentOS/RHEL 用户,使用 YUM 命令 来安装 pip 包。

$ sudo yum install python-pip

对于 openSUSE 用户,使用 Zypper 命令 来安装 pip 包。

$ sudo zypper install python-pip

最后,运行如下的 pip 命令 来在 Linux 上安装 Asciinema 工具。

$ sudo pip3 install asciinema

如何使用 Asciinema 工具来记录你的终端会话

一旦你成功的安装了 Asciinema,只需要运行如下命令来开始录制:

$ asciinema rec 2g-test
asciinema: recording asciicast to 2g-test
asciinema: press "ctrl-d" or type "exit" when you're done

出于测试的目的,运行一些简单的命令,并看一看它是否运行良好。

$ free
              total        used        free      shared  buff/cache   available
Mem:          15867        2783       10537        1264        2546       11510
Swap:         17454           0       17454

$ hostnamectl
   Static hostname: daygeek-Y700
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: 31bdeb7b833547368d230a2025d475bc
           Boot ID: c84f7e6f39394d1f8fdc4bcaa251aee2
  Operating System: Manjaro Linux
            Kernel: Linux 4.19.8-2-MANJARO
      Architecture: x86-64

$ uname -a
Linux daygeek-Y700 4.19.8-2-MANJARO #1 SMP PREEMPT Sat Dec 8 14:45:36 UTC 2018 x86_64 GNU/Linux

$ lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
Address sizes:       39 bits physical, 48 bits virtual
CPU(s):              8
On-line CPU(s) list: 0-7
Thread(s) per core:  2
Core(s) per socket:  4
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               94
Model name:          Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Stepping:            3
CPU MHz:             800.047
CPU max MHz:         3500.0000
CPU min MHz:         800.0000
BogoMIPS:            5186.00
Virtualization:      VT-x
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            6144K
NUMA node0 CPU(s):   0-7
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_add fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp flush_l1d

当你完成后,简单的按下 CTRL+D 或输入 exit 来退出录制。这个结果将会被保存在同一个目录。

$ exit
exit
asciinema: recording finished
asciinema: asciicast saved to 2g-test

如果你想要保存输出到不同的目录中,就需要提醒 Asciinema 你想要保存文件的目录。

$ asciinema rec /opt/session-record/2g-test1

我们可以使用如下命令来回放录制的会话。

$ asciinema play 2g-test

我们能够以两倍速来回放录制的会话。

$ asciinema play -s 2 2g-test

或者,我们可以以正常速度播放录制的会话,限制空闲时间为 2 秒。

$ asciinema play -i 2 2g-test

如何在网络上分享已经录制的会话

如果你想要分享录制的会话给你的朋友,只要运行下述命令上传你的会话到 asciinema.org,就可以获得一个唯一链接。

它将会在被上传 7 天后被归档。

$ asciinema upload 2g-test
View the recording at:

    https://asciinema.org/a/jdJrxhDLboeyrhzZRHsve0x8i

This installation of asciinema recorder hasn't been linked to any asciinema.org
account. All unclaimed recordings (from unknown installations like this one)
are automatically archived 7 days after upload.

If you want to preserve all recordings made on this machine, connect this
installation with asciinema.org account by opening the following link:

    https://asciinema.org/connect/10cd4f24-45b6-4f64-b737-ae0e5d12baf8

如果你想要分享录制的会话在社交媒体上,只需要点击页面底部的 “Share” 按钮。

如果任何人想要去下载这个录制,只需要点击页面底部的 “Download” 按钮,就可以将其保存在你系统里。

如何管理 asciinema.org 中的录制片段

如果你想要留存所有在这个机器上录制的片段,点击上述显示的链接并使用你在 asciinema.org 的账户登录,然后跟随这个说明继续操作,来将你的机器和该网站连接起来。

https://asciinema.org/connect/10cd4f24-45b6-4f64-b737-ae0e5d12baf8

如果你早已录制了一份,但是你没有在你的 asciinema.org 账户界面看到它,只需要运行 asciinema auth 命令来移动它们。

$ asciinema auth

Open the following URL in a web browser to link your install ID with your asciinema.org user account:

https://asciinema.org/connect/10cd4f24-45b6-4f64-b737-ae0e5d12baf8

This will associate all recordings uploaded from this machine (past and future ones) to your account, and allow you to manage them (change title/theme, delete) at asciinema.org.

如果你想直接上传文件而不是将其保存在本地,直接运行如下命令:

$ asciinema rec
asciinema: recording asciicast to /tmp/tmp6kuh4247-ascii.cast
asciinema: press "ctrl-d" or type "exit" when you're done

出于测试目的,运行下述命令,并看一看它是否运行的很好。

$ free
              total        used        free      shared  buff/cache   available
Mem:          15867        2783       10537        1264        2546       11510
Swap:         17454           0       17454

$ hostnamectl
   Static hostname: daygeek-Y700
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: 31bdeb7b833547368d230a2025d475bc
           Boot ID: c84f7e6f39394d1f8fdc4bcaa251aee2
  Operating System: Manjaro Linux
            Kernel: Linux 4.19.8-2-MANJARO
      Architecture: x86-64

$ uname -a
Linux daygeek-Y700 4.19.8-2-MANJARO #1 SMP PREEMPT Sat Dec 8 14:45:36 UTC 2018 x86_64 GNU/Linux

如果你完成了,简单的按下 CTRL+D 或输入 exit 来停止录制,然后按下回车来上传文件到 asciinema.org 网站。

这将会花费一些时间来为你的录制生成唯一链接。一旦它完成,你会看到和下面一样的样式:

$ exit
exit
asciinema: recording finished
asciinema: press "enter" to upload to asciinema.org, "ctrl-c" to save locally

View the recording at:

 https://asciinema.org/a/b7bu5OhuCy2vUH7M8RRPjsSxg

via: https://www.2daygeek.com/linux-asciinema-record-your-terminal-sessions-share-them-on-web/

作者:Magesh Maruthamuthu 选题:lujun9972 译者:Bestony 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

相关内容

告别空谈AI:荣耀三叶草战...
在人工智能浪潮席卷全球的当下,科技企业纷纷踏上 AI 发展之路。荣...
2025-07-07 20:44:07
7.4商业观察:端侧AI芯...
投资信息太多太杂,不知道什么是重点?「华彬金融观察」公众号,深度研...
2025-07-04 06:42:10
AI投资从叙事博弈走向产业...
□徐兵 上半年,AI行情上演了一场典型的资本“冷热交替”。一季度,...
2025-07-03 08:11:36
速递|谷歌“终端智能体”的...
图片来源:谷歌 谷歌正在推出一款新型 AI Agent工具,旨在...
2025-06-27 13:12:21
短短一年,是什么让移动AI...
2024年,是AI入端元年,大模型和agent被接入到各类移动终端...
2025-06-20 12:14:34
加速AI落地 荣耀与中国移...
6月19日,荣耀与中国移动在上海联合举办“中国移动&荣耀AI终端战...
2025-06-19 20:13:00

热门资讯

Helix:高级 Linux ... 说到 基于终端的文本编辑器,通常 Vim、Emacs 和 Nano 受到了关注。这并不意味着没有其他...
使用 KRAWL 扫描 Kub... 用 KRAWL 脚本来识别 Kubernetes Pod 和容器中的错误。当你使用 Kubernet...
JStock:Linux 上不... 如果你在股票市场做投资,那么你可能非常清楚投资组合管理计划有多重要。管理投资组合的目标是依据你能承受...
通过 SaltStack 管理... 我在搜索Puppet的替代品时,偶然间碰到了Salt。我喜欢puppet,但是我又爱上Salt了:)...
Epic 游戏商店现在可在 S... 现在可以在 Steam Deck 上运行 Epic 游戏商店了,几乎无懈可击! 但是,它是非官方的。...
《Apex 英雄》正式可在 S... 《Apex 英雄》现已通过 Steam Deck 验证,这使其成为支持 Linux 的顶级多人游戏之...
如何在 Github 上创建一... 学习如何复刻一个仓库,进行更改,并要求维护人员审查并合并它。你知道如何使用 git 了,你有一个 G...
2024 开年,LLUG 和你... Hi,Linuxer,2024 新年伊始,不知道你是否已经准备好迎接新的一年~ 2024 年,Lin...
什么是 KDE Connect... 什么是 KDE Connect?它的主要特性是什么?它应该如何安装?本文提供了基本的使用指南。科技日...
Opera 浏览器内置的 VP... 昨天我们报道过 Opera 浏览器内置了 VPN 服务,用户打开它可以防止他们的在线活动被窥视。不过...