命令行也可以被录制

今天在翻书时发现了一条挺好玩的命令~

在linux下借助两条命令script和scriptrepaly.

我们可以把命令行里的操作都“录制”下来。

这里做个笔记,也许以后会有用到的时候。 首先利用script命令开始录制:

1 whthomas@whthomas:~/workplace/shell$ script -t 2>timing.log -a output.session

直到我们输入exit终止文件

1 whthomas@whthomas:~/workplace/shell$ scriptplay timing.log output.session

开始播放刚刚录制的东西.

现在分析下两条命令的作用。

whthomas@whthomas:~/workplace/shell$ script -t 2>timing.log -a output.session

-t将时序的信息导出到标准错误中去,然后我们把标准错误定向到timing.log这个文件中去。

这样一来,timing.log储存了时序信息描述命令在何时被执行。

output.session 用于存储命令输出。

大家可以尝试下,满好玩的。

这玩意儿不仅可以录制,还可以做直播! 我们需要打开两个终端。

在终端一上:

whthomas@whthomas:~/workplace/shell$ mkfifo scriptfifo

在终端二上:

whthomas@whthomas:~/workplace/shell$ cat scriptfifo 

回到终端一:

whthomas@whthomas:~/workplace/shell$ script -f scriptfifo 

接着你输入什么,命令行二上就会同步给你直播了。突然觉得命令行都高端大气了!

当然最后我们可以使用exit来退出这个直播命令。

相比什么屏幕录制软件,这几条命令占的空间不过是几个KB。而且效果很棒,有木有!

原文地址:https://www.cnblogs.com/whthomas/p/3574268.html