Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know that I can redirect stdout to a file before running a script, but is there a way to access the whole output of a program that already ran? When the output is too long it gets cut out by the terminal window and I can't see the initial prints.

share|improve this question
up vote 1 down vote accepted

There are a couple of suggestions:

  1. increase the number of retained lines in your terminal window. On all of the systems I can, I usually have it set to something like 10,000 lines (or the max possible is less).
  2. (probably slightly more practical) When you know you might want to be able to capture output, start a new bash shell running and pipe the output to a file with tee (bash | tee record.txt). Any output from commands run in that shell will be put into the file "record.txt". Unfortunately, it does not capture input (including the commands you type) and shell prompts.
  3. (better) Before executing anything you think you might want to safe, use script. This will start capturing both your input and program output. When you are finished with stuff, exit the shell or type Ctrl-D. Note: the output generated by script may not be written until 'script' is finished.
share|improve this answer
You can use the script command to capture everything, including prompts and user-input. Adding it to your .profile might be a step too far though. – RedGrittyBrick Jul 29 '11 at 15:10
@RedGrittyBrick Cool, I learned something new today! – jwernerny Jul 29 '11 at 17:16
Thanks for the suggestions. So if I run the script without any of these options, everything that goes off the screen is lost forever. Is this correct? I thought that the output could be saved somewhere (for example, bash_history automatically records what I write). – nmat Jul 30 '11 at 5:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .