As title. I want to copy all output that is currently in an xfce or gnome terminal session and save to a file for further analysis.

  • Do you mean 'copy and paste all output in the xfce-terminal, or gnome-terminal window, and paste it into a file' or redirect it a command at a time (as John T thought) ? I'm afraid I can't advise on the use of those terminals (I use KDE) but I thought you meant copy-and-paste rather than redirect.
    – pavium
    Dec 7, 2009 at 3:46
  • By "save" I assumed he meant to a file. Could be either or I guess.
    – John T
    Dec 7, 2009 at 3:48
  • Yes, I mean copy all output on terminal, and save it to log file.
    – Sam Liao
    Dec 7, 2009 at 3:55
  • If you know before hand that you want to save your output, start a script. Dec 7, 2009 at 7:49
  • I wish there were another answer to this that covered getting the current text, of a command already run. It's usually when, say, I mis-typed the log4j.xml file location causing my java file to not print to the log, but to the screen, for a command that I can't repeat, that I wish I could do this.
    – Aaron R.
    Oct 7, 2014 at 21:08

7 Answers 7


Sadly I think the only really efficient/reliable solution would be to patch the pseudo-terminal code itself to do this. I've been looking for a way to do this in xfce for a while, and the cleanest answer I have at this point is: use the mouse to copy the whole buffer top to bottom, then run this:

$ xclip -selection c -o > ~/output-of-pseudo-terminal

What I really want is something that will ALWAYS log ALL my terminal output. To me, RAM and disk space are cheap, and realistically even when I accidentally hit all those stupid commands that flood the screen, a year's worth of my work on the terminal is still mere megabytes and the benefits of logging it all are many compared to how trivial it would be.

Also, while I think a patch to automatically save output is ideal, perhaps an easier workaround patch could be a command for automatically "selecting all" text and copying it - that way it could at least be combined with xclip and cron-scripted, etc. and not force us to be clumsy with the mouse :)


Instead of dragging mouse to select all text, I got a workable way though I not so like it.

  1. triple click the last line of current terminal(do not release the mouse).
  2. press SHIFT+HOME key which will lead us to the first line.
  3. drag mouse to the first line.
  4. right click , edit->copy.
  • Very Simple! Thanks
    – smac89
    Apr 25, 2020 at 18:01

Redirect it to a file:

$ example-command > ~/output.txt

Where example-command is the command that is producing the output you want to save. The tilde (~) signifies your home directory, so the file output.txt will be under your home folder containing the output of the command.

If you want all output, including errors:

$ example-command > ~/output.txt 2>&1

If you'd like it on your clipboard, you have a few options:

If there isn't a lot of output, you can highlight the output and right click to save it to your clipboard. If there is too much to highlight, pipe it to xclip (you may need to install it depending on your distro):

$ example-command | xclip

xclip allows command line interaction with the X server's clipboard.


use the command 'script'. For usage rtfm.

  • Not really an answer.
    – fixer1234
    Sep 30, 2015 at 23:59

pbcopy works pretty good :)

add this to your .bashrc or .zshrc

copy { $1 | pbcopy }

This will copy the output of the command to the buffer.

Use Ctrl+V or pbpaste to show the output.

For example:

The command copy pwd

Would output the current directory to the buffer


Pop open gEdit or vi or your favorite text editor, copy, paste, and save.

  • Problem is how to copy, too many lines. drag mouse is not a good idea.
    – Sam Liao
    Dec 7, 2009 at 6:50
  • why is mouse-dragging a bad idea? are we talking tens of lines, hundreds, or thousands? Dec 7, 2009 at 18:44

For new readers arriving on this old question, I must say that modern xfce4-terminal versions have a command for this under the menu item Terminal - Save Contents.

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.