Linux 将终端会话转储到文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7564960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:22:06  来源:igfitidea点击:

Dump terminal session to file?

linuxterminal

提问by zetah

I run gnome-terminal with unlimited scroll-line history
I want to dump text I can see in terminal to file and parse it

我使用无限滚动行历史运行 gnome-terminal
我想转储我可以在终端中看到的文本到文件并解析它

Is there a way to do it?

有没有办法做到这一点?

采纳答案by Greg Price

If you want the whole contents of the terminal history:

如果您想要终端历史记录的全部内容:

In the gnome-terminal menu, Edit > Select Alland then Edit > Copy. (Or use your favorite keyboard shortcut for the copy.)

在 gnome-terminal 菜单中,编辑 > 全选,然后编辑 > 复制。(或者使用您最喜欢的键盘快捷键进行复制。)

Then paste anywhere.

然后粘贴到任何地方。

If you want just part of the history, select with your mouse and then copy.

如果您只想要部分历史记录,请用鼠标选择然后复制。

回答by Gavin Brock

You could use the unix scriptcommand to capture things as you go.

您可以使用 unix脚本命令随时捕获事物。

回答by Noufal Ibrahim

If it's the output of a program that you want to capture and parse, simply redirect (>) it into a file

如果它是您想要捕获和解析的程序的输出,只需将>它重定向 ( ) 到一个文件中

program_with_lots_of_output > output.log

and then parse it. Append a 2>&1to that if you want standard error as well.

然后解析它。2>&1如果您还想要标准错误,请附加一个。

If you want a screen capture (i.e. including input), use the scriptprogram.

如果您想要屏幕截图(即包括输入),请使用脚本程序。

回答by Anz

You may want to use the 'tee' command. Tee bifurcates out stdout and makes a copy out the output in a file. So you can see the output and have the output stored also. Example:

您可能想要使用 'tee' 命令。Tee 将 stdout 分叉出来,并将输出复制到文件中。所以你可以看到输出并存储输出。例子:

ls | tee ls_out

ls | 三通ls_out