Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Does an elegant way exist to save the output of a command to a file after the command has been run, with the terminal window is open?

I mean once the command has been executed in the terminal. The output is still there 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?

share|improve this question
    
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 '11 at 16:02
    
@belacqua did you ever manage to find the patched version? –  Dmitry Pashkevich Aug 2 '13 at 7:38
add comment

2 Answers

up vote 6 down vote accepted

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.

share|improve this answer
1  
Addition: What i've found out so far, good tools for that purpose are screen or tmux. –  NES Jan 9 '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 3 '11 at 16:07
    
thanks, for the tip. –  NES Feb 6 '11 at 10:42
    
Edit->Select All in gnome terminal can help you highlight all that's in the buffer –  Dmitry Pashkevich Aug 2 '13 at 7:38
add comment

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.

share|improve this answer
1  
not exactly, what i intended, but that's also very helpful. thanks –  NES Jan 9 '11 at 15:51
1  
This is totally what the OP asked for, but you just saved me HUGE efforts! Thanks! =) –  Bruce Connor May 13 '11 at 19:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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