Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

This question already has an answer here:

Is there any way to copy current command (line typed in bash prompt) in terminal to X-clipboard without involving a mouse?

share|improve this question

marked as duplicate by Gilles, slm, Anthon, rahmu, Chris Down Jul 25 '13 at 12:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

What is the “current command”? If you know what to copy, you can use xclip. – Marco Jul 24 '13 at 10:01
@Marco - Thank you - I expanded question. As for xclip, I am a newbie and do not know what it about. Could you explain? – Loom Jul 24 '13 at 10:09
@Gilles - Frankly, I do not really understand how the knowledge of how to put the selected text to the clipboard can help with putting the current command to the clipboard. Is there a keyboard shortcut, that allows to select the current command from bash prompt? – Loom Jul 25 '13 at 7:28
@Loom How does the copy_line_to_x_clipboard function in my answer differ from what you're asking? If you're asking for a shortcut out of the box, then no, it doesn't exist, that's why I wrote a function. You can bind this function to whatever key you like (I also show how to do this in my answer). – Gilles Jul 25 '13 at 11:27

Yes, first you have to install xclip. (sudo apt-get install xclip)

Then to copy previous line:

echo !! | xclip

To Paste: Middle click or

xclip -o

For example:

Wed Jul 24 15:46:54 IST 2013
echo !! | xclip

xclip -o

To copy Output of any command: <command> | xclip

However, this may fail if the command has special characters.

share|improve this answer
That fails if the command contains just about any special character. – Gilles Jul 24 '13 at 22:02

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