当我们要进行屏幕录制时,经常选择视频方式,但这种方式产生的视频文件很大,可以用script命令录制终端会话,记录命令和时序以及命令结果,这样大小通常只有几KB,exit可以退出录制:
[student@myhost ~]$ script -t 2> timing.log -a output.session
Script started, file is output.session
[student@myhost ~]$ ls
4 aout d Downloads findresultsvv log.txt o Pictures stderr.txt testdir vimfile.txt
5 b Desktop file1 ggg.tar longlisting.txt out Public stdout.txt timing.log
a c Documents file2 hhh Music output.session public_html Templates Videos
[student@myhost ~]$ cd ..
[student@myhost home]$ cd student/
[student@myhost ~]$ cat a
space:
tab:
[student@myhost ~]$ exit
exit
Script done, file is output.session
[student@myhost ~]$ scriptreplay timing.log output.session
[student@myhost ~]$ ls
4 aout d Downloads findresultsvv log.txt o Pictures stderr.txt testdir vimfile.txt
5 b Desktop file1 ggg.tar longlisting.txt out Public stdout.txt timing.log
a c Documents file2 hhh Music output.session public_html Templates Videos
[student@myhost ~]$ cd ..
[student@myhost home]$ cd student/
[student@myhost ~]$ cat a
space:
tab:
[student@myhost ~]$ exit
以上演示中,-t选项代表将时序数据以stderr形式产生,之后将时序数据导入timing.log(2> timing.log),-a选项表示将屏幕上出现的内容保存到哪个文件里。
保存后,我们可以将这两个文件放到任意终端上进行回放,但只保证同类终端能正常播放,因为转义符可能被以另一种方式转义,导致与预期的输出不一致,命令"scriptreplay 时序文件 内容文件"即可回放。