Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to copy an output on a GNOME terminal to clipboard from command line.

I'd like to be able to paste text from my console textfiles smoothly to Firefox.

share|improve this question

You can highlight the text then right click and select copy, or pipe it to xclip:

some-command | xclip

xclip may or may not be available depending on your distribution.

share|improve this answer
    
xsel is similar to xclip and can be used similarly. – alfplayer Dec 14 '09 at 23:19
    
Simply calling xclip doesn't do it by default, but if you append it with the following options the -sel clip or -selection clipboard it you can paste the output to your browser etc.. echo "http://superuser.com/" | xclip -sel clip, alt-tab to chrome, ctrl+l, ctrl+v, enter... vola! P.S. I don't know if xsel has similar options to make it work. By default it doesn't work. – Timo Lehto Aug 15 '12 at 9:45

You can also just mark the terminal output you want to copy and it is copied to your clipboard automatically.

share|improve this answer
    
Technically it's called the cut buffer, the clipboard is something else. – TRS-80 Jan 14 '10 at 2:55

It's an old question but I thought it deserves a working answer. Either xsel or xclip can do this job. Personally I prefer to use xsel, which has a cleaner syntax.

echo "helloworld" | xsel -b

Then change to some app and do a paste (with CTRL-V, the paste option, etc.).

That's it!

What if you are doing the opposite, and copy some text in your browser and want to paste it into your terminal? (Well, of course you can just paste.) Or type:

xsel -b                                           # outputs "helloworld"

X has got 3 different selections or clipboards. The "primary" one is the one that activates with the middle mouse button. That's what you get if you call xsel or xclip without any arguments. To get access to the "clipboard" that is used for copy/paste, CTRL-C/CTRL-V etc, the -b is required.

I recommend you do use the -b option and interoperate with the clipboard rather than the X11 middle-click "primary" selection -- because in the transition from X to Wayland, access to the X11 "primary" selection may not survive in Gnome or Wayland. Here's a relevant Gnome bugzilla thread.

Both xsel and xclip interact with X, not with Gnome directly, but so long as your display manager is running XWayland (which it should do for years to come), then xsel -b will continue to work and be safe to use in scripts. Nothing is 100% future proof but xsel -b is fine for now.

If you prefer to use xclip, the syntax equivalent for the two examples above is:

echo "helloworld" | xclip -selection c
xclip -o -selection c                             # outputs "helloworld"
share|improve this answer

After selecting the text, press Ctrl-Shift-C to copy it to the clipboard. The extra Shift is required as Ctrl-Cis already used in shells. Similarly, to paste, press Ctrl-Shift-V.

You can also just select it then middle-click in Firefox to paste it. This uses the cut buffer, which is slightly different to the clibpoard.

Bonus gnome-terminal tip - Ctrl-click a url to automatically open it in your default browser.

share|improve this answer

You must log in to answer this question.

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