Terminal *output* history?

21

9

I make extensive use of the functions to navigate through the command history in my terminal; I wonder if there is some way to navigate the command output history as well? (besides keeping a large histsize and leaning on the pgup key)

I cannot just 'rerun the command', as in my particular situation the source of the commands changes; I frequently need to look back at the output of a previous change.

Hacks welcome.

Thanks!

Edit 2010:

I've given 'tee' the credit; among all the methods to log your session elsewhere, it's the most broadly applicable (i.e. it's part of gnu coreutils, and doesnt require a specific shell or utility to work). It wasn't really what I was looking for, but I realize that such a thing doesn't really exist.

The closest approximation I can think of is to use something like screen (byobu/tmux) that logs to file, and write (and keybind) a custom command to page/search through that logfile (think less paging by prompt rather than screen). Thanks everyone.

Edit 2012:

@Dustin Kirkland's answer is clearly best, at least generally; the terminal's scrollback buffer is least-intrusive way to navigate command output history. Byobu appears to have a large default number of history lines saved (10K; tmux has 2K, GNU screen 100), and it allows regex searches (a cursory look indicates that GNU screen has no scrollback search, and tmux has only plaintext search).

mikewaters

Posted 2010-09-09T17:54:38.917

Reputation: 1 323

Answers

4

You mention using byobu...

That's certainly one way of doing it. Byobu stores 10K lines of scrollback history per window or per split (pane).

You can enter scrollback easily by pressing Alt-PageUp, Alt-PageDown, or F7. Once you're in scrollback mode, you can search forward and backward using vi-like commands. Use /regex to search forward, and ?regex to search backward.

Dustin Kirkland

Posted 2010-09-09T17:54:38.917

Reputation: 7 101

Where is scrollback history stored, and is there a way to make it persist between sessions? I.e.: Open terminal with Byobu, run some commands, call exit, close terminal, open a new terminal with Byobu and still have the previous session. – Darrel Holt – 2019-07-31T16:53:25.927

11

You can use tee to send your command output to a file and to the terminal at the same time.

Carl Norum

Posted 2010-09-09T17:54:38.917

Reputation: 2 621

8

You can use script to log your terminal session to a file. If you always want this to happen then add a suitable script command to your .login.

$ man script

Paul R

Posted 2010-09-09T17:54:38.917

Reputation: 4 717

5

screen can be set to log output.

One way to start it, within a running screen session, is to press Ctrl-a, then :, then enter log.

From 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.

Paused until further notice.

Posted 2010-09-09T17:54:38.917

Reputation: 86 075

@SQB: I've expanded my answer. – Paused until further notice. – 2015-07-22T16:48:54.857

5

use screen -L

after exiting shell session (exit command) you get a logfile in the same directory you started screen

then you can view the output with more or less -R

wieczorek1990

Posted 2010-09-09T17:54:38.917

Reputation: 151

3

bash does keep the history of what you did, but not the output from the commands. It could potentially be huge and frequently isn't useful.

Jay

Posted 2010-09-09T17:54:38.917

Reputation: 165