有没有什么办法可以将终端窗口上发生的任何事情的内容保存到文件中?
我想将正在执行的每个命令及其输出保存到文件中以跟踪更改历史记录,并且我想在终端上永久启用它。
请问有什么建议吗?
答案1
script
,从bsdutils
包中得到的就是你想要的工具。
script my.log
# bunch of commands
exit
您输入的所有命令以及它们的所有输出(包括光标控制,这取决于的设置$TERM
)都将保存在中my.log
。
从man
页面:
bionic (1) script.1.gz
Provided by: bsdutils_2.31.1-0.4ubuntu3_amd64 bug
NAME
script - make typescript of terminal session
SYNOPSIS
script [options] [file]
DESCRIPTION
script makes a typescript of everything displayed on your terminal. It is useful for
students who need a hardcopy record of an interactive session as proof of an assignment,
as the typescript file can be printed out later with lpr(1).
If the argument file is given, script saves the dialogue in this file. If no filename is
given, the dialogue is saved in the file typescript.