将过去的 GNU 屏幕输出保存到文件

Sza*_*lcs 6 logs gnu-screen

我已经运行了几天的 GNU 屏幕会话。我发现自己需要将终端内容(我可以向上滚动查看)保存到一个文件中。这可能吗?我估计它在 5000 行以下。

我找到了一种方法来设置屏幕以将未来的输出记录到文件中。但在这种情况下,我还需要保存过去的输出(或尽可能多的现有输出)。

Ark*_*zyk 10

您可以使用hardcopy -h命令将当前滚动缓冲区的内容保存到文件中。如中所述man screen

   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.
Run Code Online (Sandbox Code Playgroud)

你说:

我估计不会超过5000行。

5000行确实很多。滚动缓冲区的默认长度 screen仅为 100,而不是 ~5000 行。除非您 screen使用较大的滚动缓冲区设置启动会话,否则将无法检索滚动缓冲区的所有约 5000 行。

  • 在按下“^a:”之前可以输入该命令。 (2认同)

Wil*_*ard 7

一种方法是使用复制模式复制整个回滚历史记录,然后将其转储到文件中。(可能有更好的方法。)

使用默认的键绑定,这将类似于:

  • Ctrl-A 向屏幕发送命令
  • [进入复印模式
  • g去顶部
  • 空格键将回滚缓冲区的开头(您所在的位置)标记为要复制的文本的开头
  • G走到最后
  • 输入以标记要复制的文本的结尾,然后复制。

然后打开vim,运行:set paste以避免自动缩进等问题,然后使用Ctrl-A ]粘贴。