14

Does an elegant way exist to save the output of a command to a file after the command has been run, while the terminal window is open i.e. once the command has been executed in the terminal?

The output is still present in terminal. Now I could copy & paste all the lines and save it to a file.

But perhaps does a method exist to somehow write the output buffer of a terminal window to a file or even better the output of an already executed command?

NES
  • 33,975
  • There was supposed to be a patch to gnome-terminal to do exactly this -- to save the scrollback buffer to a file. It's out there somewhere, but I can't find what version of gnome-terminal it is actually integrated into. I believe it something like a simple 'Save to file' option to the file menu. – belacqua Feb 03 '11 at 16:02
  • @belacqua did you ever manage to find the patched version? – Dmitry Pashkevich Aug 02 '13 at 07:38

2 Answers2

8

You appear to have a number of options, but gnome-terminal doesn't support logging to a file by itself.

  • You can run the script command before your output in order to accomplish this. See this Launchapd Q&A for more.

  • You can install and use a different terminal instead of gnome-terminal, which supports logging all output to a file, such as Putty. There may be others.

  • You can simply highlight the text output you require, then use CTRL-SHIFT-C to copy the text.

Scaine
  • 11,239
  • 1
    Addition: What i've found out so far, good tools for that purpose are screen or tmux. – NES Jan 09 '11 at 21:42
  • 1
    @NES If screen works, byobu might as well. Dustin Kirkland (one of the Ubuntu core devs) has worked to improve screen in that package (in the repos). Though I haven't used it lately -- usually terminator. – belacqua Feb 03 '11 at 16:07
  • 3
    Edit->Select All in gnome terminal can help you highlight all that's in the buffer – Dmitry Pashkevich Aug 02 '13 at 07:38
6

If you are looking for a way to save the output of a command in a file and also display it in the terminal, then use tee command.

command | tee filename

output of the command is displayed in the terminal as well as in the file.

balki
  • 2,330