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?

2
  • 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 3, 2011 at 16:02
  • @belacqua did you ever manage to find the patched version? Aug 2, 2013 at 7:38

2 Answers 2

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.

3
  • 1
    Addition: What i've found out so far, good tools for that purpose are screen or tmux.
    – NES
    Jan 9, 2011 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 3, 2011 at 16:07
  • 3
    Edit->Select All in gnome terminal can help you highlight all that's in the buffer Aug 2, 2013 at 7: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.

2
  • 1
    not exactly, what i intended, but that's also very helpful. thanks
    – NES
    Jan 9, 2011 at 15:51
  • 1
    This is totally what the OP asked for, but you just saved me HUGE efforts! Thanks! =)
    – Malabarba
    May 13, 2011 at 19:46

You must log in to answer this question.

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