Server Fault is a question and answer site for system and network administrators. 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

Is it possible to redirect the output of your terminal in linux to the clipboard? Right now I am using Ubuntu 9.10 and I simply right click and "copy" the selected text. It would be a lot easier if I could go like this...

grep sometext myfile || clipboard
share|improve this question
up vote 5 down vote accepted

The xclip package will do this. Another similar tool that is also frequently useful is pastebinit.

Usage is simple just do something like cat /etc/passwd | xclip.

It is also possible, to take the contents of the clipboard and use it with a command like xclip -out | grep 'foo'.

share|improve this answer
This makes my day. – bstpierre Jan 22 '10 at 23:56
Thanks! Glad to find this but somehow stunned that Linux doesn't have a standard program already installed for this.... – P.Windridge Jan 27 at 22:39

The command doesn't work just this way:

ls | xclip

You should use this variant to make it work:

ls | xclip -selection clipboard

hmm... rather long for such an easy task...

share|improve this answer

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.