我已经运行了几天的 GNU 屏幕会话。我发现自己需要将终端内容(我可以向上滚动查看)保存到一个文件中。这可能吗?我估计它在 5000 行以下。
我找到了一种方法来设置屏幕以将未来的输出记录到文件中。但在这种情况下,我还需要保存过去的输出(或尽可能多的现有输出)。
Ark*_*zyk 10
您可以使用hardcopy -h
命令将当前滚动缓冲区的内容保存到文件中。如中所述man screen
:
Run Code Online (Sandbox Code Playgroud)hardcopy [-h] [file] Writes out the currently displayed image to the file file, or, if no filename is specified, to hardcopy.n in the default directory, where n is the number of the current window. This either appends or overwrites the file if it exists. See below. If the option -h is specified, dump also the contents of the scrollback buffer.
你说:
我估计不会超过5000行。
5000行确实很多。滚动缓冲区的默认长度
screen
仅为 100,而不是 ~5000 行。除非您
screen
使用较大的滚动缓冲区设置启动会话,否则将无法检索滚动缓冲区的所有约 5000 行。
一种方法是使用复制模式复制整个回滚历史记录,然后将其转储到文件中。(可能有更好的方法。)
使用默认的键绑定,这将类似于:
[
进入复印模式g
去顶部G
走到最后然后打开vim,运行:set paste
以避免自动缩进等问题,然后使用Ctrl-A
]
粘贴。