Is there any way to log every that was displayed in gnome-terminal?

for example I have a complex command

doSomethingThatPrintoutsAlot ; doSomethingThatPrintoutsAlot2 ; doSomethingThatPrintoutsAlot3

I can add > file, but than I would have to do it for each command and I have to use tail in another console to see the output. maybe gnome-terminal support logging everything?

there is .bash_history, so .... it might also support this.

  • 1
    While logging (as asked and answered about) is usually preferable, sometimes might want to run multiple commands on a line and redirect all the output to a file. In bash (the shell used by default in the Terminal), you can do that with ( doSomethingThatPrintoutsAlot ; doSomethingThatPrintoutsAlot2 ; doSomethingThatPrintoutsAlot3 ) > file. Also, any time you use > (or >>), only output is redirected--the file would not contain characters you entered yourself while the command ran. And they don't include stderr (most error messages): for that too, use &> (and &>>). – Eliah Kagan Nov 28 '11 at 11:00
  • 1
    Also, if you want to run a single command (or a few commands strung together as described above) and have the output go to a file and also see it on the screen, then: Instead of command > file, use command | tee file. Instead of command >> file, use command | tee -a file. Instead of command &> file, use command 2>&1 | tee file. Instead of command &>> file, use command 2>&1 | tee -a file. See also tee's manpage and the TDLP Advanced Bash Scripting Guide. – Eliah Kagan Nov 28 '11 at 11:08
  • @Eliah Kagan thx, that is very helpful. – UAdapter Nov 28 '11 at 12:14

The .bash_history file only stores the command history, not the output. Skimming through man bash it does not seem to support that kind of logging.

However there is the script command that is able to log the output of any terminal. The usage is quite simple:

script ~/mylog
Script started, file is /home/-----/mylog
(commands that produce output)
Script done, file is /home/------/mylog

The output can be read from ~/mylog.

  • +1, I was just writing a similar answer. I would add that a quick and somewhat less flexible alternative could be to set the gnome-terminal scrollback to Unlimited. – enzotib Nov 28 '11 at 9:59
  • Thanks! I was wondering if there are any alternative solutions. I thought about screen but that seemed to be a bit overkill... – lgarzo Nov 28 '11 at 10:37

This does not answer your question directly since you're asking about gnome-terminal, but for completeness sake: konsole, the terminal emulator from KDE, makes this as easy as File - Save Output As... - which saves everything in the terminal's scrollback buffer.

It is also possible to set the number of lines stored in the scrollback buffer to unlimited, so this would work even for a very long output.

There's also "Clear Scrollback" option.

You can easily install konsole in Gnome, but that would pull down a few KDE dependencies.

  • good to know, thx – UAdapter Nov 28 '11 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.