将 GNU 屏幕回滚缓冲区复制到文件(扩展硬拷贝)
如何轻松地将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
要将回滚缓冲区的全部内容写入文件,请键入
Ctrl + A 和 :
要进入命令模式,请选择
路径:要保存屏幕日志文件的位置。
示例:
在旧版本的
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.
Example:
In older versions of
screen
, if you just dohardcopy -h
, it just writes to the file-h
. This was fixed in version 4.2.0, sohardcopy -h
writes tohardcopy.N
whereN
is the current window number.按 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.
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
这对我有用:
进入编辑模式(
~
)并输入:它创建了一个巨大的文件,其中 98% 是空的,但我的日志完全存在于剩余的 2% 中。
This worked for me:
Enter edit mode (
~
) and type:It created a huge file, of which 98% was empty, but my logs were fully present in remaining 2%.
尝试使用 Hardcopy -h 来包含整个缓冲区。
Try
hardcopy -h
to include the whole buffer.我的两分钱
除了比尔的正确答案之外,由于这里没有答案解决了获取内容的需要从命令行的 GNU 屏幕缓冲区,我建议使用
screen -X
命令:而不必点击 Ctrl+a,然后是 :,然后点击
hardcopy [-h] /path/to/somefile
,我尝试从命令行运行它。所以:基本上
或者
会完成这项工作。
关于
-h
开关,来自man screen
:从另一个屏幕窗口
但是,如果您使用多个窗口,您可以通过以下方式获取特定窗口的内容:
转储窗口1的内容到文件
/tmp/tempfile
。即使没有附加:
您也可以从外部使用
-x
开关:或
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
or
will do the job.
About
-h
switch, fromman screen
:From another screen window
But, if you use more than one window, you could get content of specific window by:
for dumping content of window 1 to file
/tmp/tempfile
.Even not attached:
And you could use
-x
switch from outside:or
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'.
执行 Ctrl + A、H。
这会将当前屏幕保存到硬拷贝文件中,例如屏幕 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.