Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

Say I've typed the following long command into the command line

 $ some very long command that I want to copy to the clipboard

How can I get this onto the system clipboard efficiently? I'm using Gnome Terminal 2.23.1.

I know that I can get the mouse and highlight it and copy it, but I want a general keyboard solution.

It would also be good if it generalised to multiple command-line programs.

For example, in bash in vi mode, I can press v and then edit the command in vim, and thus use Vim's copy to clipboard features, but this doesn't work when using R on the command-line. It's also a bit slow.

I'd like it if in vi-mode, I could press yy and copy the contents of the line to the system clipboard, but this doesn't seem to work. Furthermore any yanking commands don't seem to copy contents to the system clipboard; they appear to only copy to a buffer used by bash.


After posting I found

share|improve this question
Not exactly what you ask: using screen you can achieve what you ask following this answer:… – enzotib Oct 5 '11 at 8:04
Following this answer ( ), you can enable Mouse Keys in Universal Access and use the number keypad to move the mouse around, with the number five acting as a click. When it's quickly double clicked it will select the word the pointer is hovering over. When it's quickly triple clicked, it will select the entire line. This along with the answers on how to copy (Ctrl-Shift-C) should do most of what you need. – James Jul 28 '14 at 22:22

You could also use a clipboard manager like parcellite. It's a GTK+ clipboard manager which also has command-line clipboard capabilities

You can use it via command-line by

echo "some very long command that I want to copy to the clipboard" | parcellite
parcellite "some very long command that I want to copy to the clipboard"

It is not installed by default and so you'll have to install parcellite by sudo apt-get install parcellite

share|improve this answer
thanks, at least when I'm in bash, I've sometimes used echo my command | xclip -se c; however, when the command has quotations and other special characters, echo often wont copy the command literally. – Jeromy Anglim Oct 5 '11 at 8:51

So the closes I have be able to get is by using the history and xclip in conjunction doing this

echo !! | xclip

This will put the last command on the the center button clipboard. I am still searching for something better though as I would like to get it down to one command. However I get hung up because history doesn't function in shell scripts and I don't know that there is a way to use !! properly in an alias. Of course this doesn't appear to be quite what your asking for my intention is to use this for taking notes of what I am doing. Any thoughs?

share|improve this answer
Also, there's still the issue of how do you copy commands with quotes. – Jeromy Anglim Oct 16 '11 at 0:57

You should be able to use Ctrl+Shift+C for Copy and Ctrl+Shift+V for Paste anywhere in the Terminal.

share|improve this answer
You still need the mouse to select the text. – enzotib Oct 5 '11 at 7:44
doh! very valid point – Dirk Hartzer Waldeck Oct 5 '11 at 8:06
Which raises the question, is it possible to customise the terminal or bash to be able to select text using the keyboard? – Jeromy Anglim Oct 5 '11 at 8:52
@JeromyAnglim Related: – Nikos Alexandris Jul 5 '13 at 8:16

Your Answer


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.