终端*输出*历史?

mik*_*ers 25 bash history byobu

我广泛使用这些功能来浏览终端中的命令历史记录;我想知道是否还有某种方法可以导航命令输出历史记录?(除了保持大的 histsize 并依靠 pgup 键)

我不能只是“重新运行命令”,因为在我的特定情况下,命令的来源会发生变化;我经常需要回顾以前更改的输出。

欢迎黑客。

谢谢!

2010年编辑:

我给了 'tee' 功劳;在其他地方记录会话的所有方法中,它是最广泛适用的(即它是 gnu coreutils 的一部分,并且不需要特定的 shell 或实用程序即可工作)。这不是我真正要寻找的东西,但我意识到这样的东西并不存在。

我能想到的最接近的近似方法是使用类似screen(byobu/tmux) 的东西记录到文件,并编写(和键绑定)一个自定义命令来页面/搜索该日志文件(想想less按提示而不是屏幕进行分页)。谢谢大家。

2012年编辑:

@Dustin Kirkland 的回答显然是最好的,至少一般来说是这样;终端的回滚缓冲区是导航命令输出历史记录的侵入性最小的方式。Byobu 似乎保存了大量的默认历史记录行数(10K;tmux 有 2K,GNU screen 100),并且它允许正则表达式搜索(粗略的观察表明 GNU screen 没有回滚搜索,而 tmux 只有纯文本搜索)。

Car*_*rum 11

您可以使用tee将命令输出同时发送到文件和终端。


Pau*_*l R 8

您可以使用script将终端会话记录到文件中。如果你总是希望这种情况发生,那么script在你的.login.

$ man script


Dus*_*and 6

你提到使用byobu ...

这当然是一种方法。Byobu 每个窗口或每个分区(窗格)存储 10K 行的回滚历史记录。

Alt您可以通过按- PageUpAlt-PageDown或轻松进入回滚F7。进入回滚模式后,您可以使用类似 vi 的命令向前和向后搜索。用于/regex向前搜索和?regex向后搜索。


Jay*_*Jay 5

bash 确实会保留您所做操作的历史记录,但不会保留命令的输出。它可能很大并且常常没有用。


Den*_*son 5

screen 可以设置为日志输出。

在正在运行的screen会话中启动它的一种方法是按Ctrl- a,然后按:,然后输入log

来自man screen

log [on|off]

Start/stop writing output of the current window to a file "screenlog.n" in the 
window's default directory, where n is the number  of  the  current  window.
This filename can be changed with the `logfile' command. If no parameter is
given, the state of logging is toggled. The session log is appended to the
previous contents of the file if it already  exists.  The current contents and
the contents of the scrollback history are not included in the session log.
Default is `off'.

logfile filename
logfile flush secs

Defines  the  name  the  log files will get. The default is "screenlog.%n". The 
second form changes the number of seconds screen will wait before flushing the
logfile buffer to the file-system. The default value is 10 seconds.
Run Code Online (Sandbox Code Playgroud)


小智 5

screen -L

退出 shell 会话(exit命令)后,您会在启动的同一目录中获得一个日志文件screen

然后您可以使用more或查看输出less -R