作家Philip G. Ezolt在其作品<<Optimizing Linux Performance: A Hands On Guide to Linux Performance Tools>>的1.1章节中建议读者在尝试解决Linux问题的时候,将在终端上跑的命令都完整记录下来,以便后续进行问题复现或者是回查。其中还重点推荐了这个script命令,这一节我们来一起看看这到底是个什么命令。
It is better just to record exactly what you typed. You can then reproduce the exact command line for a future test, and when reviewing past results, you can also see exactly what you measured. The Linux command script (described in detail in Chapter 8, “Utility Tools: Performance Tool Helpers”) or “cut and paste” from a terminal is a good way to do this.
我是T型人小付,一位坚持终身学习的互联网从业者。喜欢我的博客欢迎在csdn上关注我,如果有问题欢迎在底下的评论区交流,谢谢。
简单介绍
script
命令用来记录终端的行为及结果,并存储成本地文件,可以直接用编辑器打开进行查看。同时可以记录时间轴信息,利用scriptreplay
命令进行动态查看。
使用方法详解
利用script -h
查看其帮助文档,如下
[root@testmachine ~]# script -h
Usage:
script [options] [file]
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
-q, --quiet be quiet
-t, --timing[=<file>] output timing data to stderr (or to FILE)
-V, --version output version information and exit
-h, --help display this help and exit
常规使用
首先这个命令是可以不接任何参数直接跑的,例如
[root@testmachine ~]# script
Script started