将 GNU 屏幕回滚缓冲区复制到文件(扩展硬拷贝)

发布于 2024-10-14 03:00:37 字数 360 浏览 4 评论 0原文

如何轻松地将 GNU 屏幕回滚缓冲区复制到文件?即,“硬拷贝”命令的更强大版本?

在GNU屏幕中,我可以使用“Ctrl + A Esc”进入回滚 缓冲。然后,我可以标记整个缓冲区并使用“Ctrl + A Ctrl + ]”将其粘贴到Emacs 缓冲区,从而将其保存到文件中。

然而,这很乏味。是否有一个屏幕命令可以简单地将回滚缓冲区复制到文件中,就像“硬复制”对屏幕可见部分所做的那样?

How do I easily copy the GNU Screen scrollback buffer to a file? I.e., a more powerful version of the 'hardcopy' command?

In GNU screen, I can use "Ctrl + A Esc" to enter the scrollback
buffer. I could then mark the entire buffer and use "Ctrl + A Ctrl + ]" to paste it into an Emacs buffer, thus saving it to a file.

However, this is tedious. Is there a Screen command that'll simply copy the scrollback buffer to a file, like 'hardcopy' does for the visible portion of the screen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

浅暮の光 2024-10-21 03:00:37

要将回滚缓冲区的全部内容写入文件,请键入

Ctrl + A:
要进入命令模式,请选择

路径:要保存屏幕日志文件的位置。

hardcopy -h <path/filename>

示例:

hardcopy -h <home/admin/myScreen.log>

在旧版本的 screen 中,如果您只执行 hardcopy -h,它只会写入文件 -h。此问题已在版本 4.2.0 中修复,因此 hardcopy -h 写入 hardcopy.N,其中 N 是当前窗口号。

To write the entire contents of the scrollback buffer to a file, type

Ctrl + A and :
to get to command mode, then

path: location where you want to save the screen log file.

hardcopy -h <path/filename>

Example:

hardcopy -h <home/admin/myScreen.log>

In older versions of screen, if you just do hardcopy -h, it just writes to the file -h. This was fixed in version 4.2.0, so hardcopy -h writes to hardcopy.N where N is the current window number.

橘寄 2024-10-21 03:00:37

Ctrl+A :bufferfile /tmp/somefile.txt ENTER,然后按 Ctrl+A >

这会将缓冲区的当前内容写入指定文件。

Press Ctrl+A :bufferfile /tmp/somefile.txt ENTER, and then Ctrl+A >

This will write the current contents of the buffer to the named file.

神魇的王 2024-10-21 03:00:37

TL;DR: ^A:writebuf

OP似乎想要一种方法来使用在执行 ^A[ 时获得的缓冲区的选定部分,使用空格作为开始选择文本并完成,然后不要使用 ^A] 进行粘贴,而是将缓冲区的所选部分保存到文件中。

这有效:

^A:writebuf

注意:writebuf 中有一个“f”

TL;DR: ^A:writebuf <filename>

The OP seems to want a way to use the selected portion of the buffer you get when doing a ^A[ , selecting text using space as the start and finish, and then instead of using ^A] to paste, save the resulting selected portion of the buffer to a file.

This worked:

^A:writebuf <filename>

Note: one 'f' in writebuf

心清如水 2024-10-21 03:00:37

这对我有用:

进入编辑模式(~)并输入:

:hardcopy -h buff_file

它创建了一个巨大的文件,其中 98% 是空的,但我的日志完全存在于剩余的 2% 中。

This worked for me:

Enter edit mode (~) and type:

:hardcopy -h buff_file

It created a huge file, of which 98% was empty, but my logs were fully present in remaining 2%.

护你周全 2024-10-21 03:00:37

尝试使用 Hardcopy -h 来包含整个缓冲区。

Try hardcopy -h to include the whole buffer.

挽清梦 2024-10-21 03:00:37

我的两分钱

除了比尔的正确答案之外,由于这里没有答案解决了获取内容的需要从命令行的 GNU 屏幕缓冲区,我建议使用 screen -X 命令:

而不必点击 Ctrl+a,然后是 :,然后点击 hardcopy [-h] /path/to/somefile,我尝试从命令行运行它。所以:

基本上

screen -X hardcopy /tmp/tempfile

或者

screen -X hardcopy -h /tmp/tempfile

会完成这项工作。

关于 -h 开关,来自 man screen

如果指定了选项-h,还转储回滚缓冲区的内容。

从另一个屏幕窗口

但是,如果您使用多个窗口,您可以通过以下方式获取特定窗口的内容:

screen -X at 1 hardcopy /tmp/tempfile

screen -X at 1 hardcopy -h /tmp/tempfile

转储窗口1的内容到文件/tmp/tempfile

即使没有附加:

您也可以从外部使用 -x 开关:

screen -x -X hardcopy /tmp/tempfile

screen -x sessionName -X hardcopy /tmp/tempfile

screen -x sessionName -X at 1 hardcopy /tmp/tempfile

screen -x sessionName -X at 1 hardcopy -h /tmp/tempfile

My two cents

In addition to Bill's correct answer, and as no answer here address the need of getting de content of GNU screen buffer from command line, I would suggest the use of screen -X command:

Instead of having to hit Ctrl+a, followed by :, then hitting hardcopy [-h] /path/to/somefile, I've tried to run this from command line. So:

Basically

screen -X hardcopy /tmp/tempfile

or

screen -X hardcopy -h /tmp/tempfile

will do the job.

About -h switch, from man screen:

If the option -h is specified, dump also the contents of the scrollback buffer.

From another screen window

But, if you use more than one window, you could get content of specific window by:

screen -X at 1 hardcopy /tmp/tempfile

screen -X at 1 hardcopy -h /tmp/tempfile

for dumping content of window 1 to file /tmp/tempfile.

Even not attached:

And you could use -x switch from outside:

screen -x -X hardcopy /tmp/tempfile

or

screen -x sessionName -X hardcopy /tmp/tempfile

screen -x sessionName -X at 1 hardcopy /tmp/tempfile

screen -x sessionName -X at 1 hardcopy -h /tmp/tempfile
夜空下最亮的亮点 2024-10-21 03:00:37

Ctrl + A:,然后发出命令“登录”。

或者在您的 .screenrc 文件中将其设置为默认值“deflog on”。

Ctrl + A, :, and issue the command 'log on'.

Or set it as the default in your .screenrc file as 'deflog on'.

叹沉浮 2024-10-21 03:00:37

执行 Ctrl + AH

这会将当前屏幕保存到硬拷贝文件中,例如屏幕 0 的 Hardcopy.0。这似乎是比 Ctrl + A, 更快的方法:并输入硬拷贝命令。

Do Ctrl + A, H.

That saves the current screen into a hard copy file, e.g., hardcopy.0 for screen 0. It seems to be a quicker way than going Ctrl + A, : and typing the hardcopy command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文