linux script命令的使用

文章介绍了如何使用Linux命令script来记录终端命令日志,包括如何追加记录、输出时序文件。同时提到了scriptreplay命令用于回放这些记录,以及可选的参数如timing和divisor来调整播放速度。另外,文章还提及了terminalizer工具,它能录制终端会话并生成gif动画。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

平常记录终端里的一些命令log或操作记录等,script可以试试看:

script --help

Usage:
 script [options] [file]

Make a typescript of a terminal session.

Options:
 -a, --append                  append the output
 -c, --command <command>       run command rather than interactive shell
 -e, --return                  return exit code of the child process
 -f, --flush                   run flush after each write
     --force                   use output file even when it is a link
 -o, --output-limit <size>     terminate if output files exceed size
 -q, --quiet                   be quiet
 -t[<file>], --timing[=<file>] output timing data to stderr or to FILE
 -h, --help                    display this help
 -V, --version                 display version

For more details see script(1).
  1. 记录log:

script -f note.log,输出到指定文件,可以边录log边看。-a则是追加记录到文件里。-t则是输出时序文件,适用于录过回放演示操作。

ex:script -f -t 2>time.log -a note.log

  1. 回放log:

scriptreplay --help

Usage:
 scriptreplay [-t] timingfile [typescript] [divisor]

Play back terminal typescripts, using timing information.

Options:
 -t, --timing <file>     script timing output file
 -s, --typescript <file> script terminal session output file
 -d, --divisor <num>     speed up or slow down execution with time divisor
 -m, --maxdelay <num>    wait at most this many seconds between updates
 -h, --help              display this help
 -V, --version           display version

For more details see scriptreplay(1).

ex:scriptreplay time.log note.log

终端会输出刚才的操作记录。

注意time.log不能少且要放在note.log前面。

  1. 退出

exit
Script done, file is note.log

PS:

还具有录制终端功能的tool:terminalizer

将录制的file做成gif文件:terminalizer、imagemagick(convert)

参考:

https://blog.youkuaiyun.com/ouyang_peng/article/details/78818492

https://blog.youkuaiyun.com/weixin_34293059/article/details/91715710

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值