Copy / pipe text from command line to clipboard and vise versa

xclip is command line interface to X selections/clipboard that is designed to run on any system with any X11 implementation, with xclip, we can not easily manipulate the data on the clipboard under a terminal in X11, no need to open a file for just copy its content anymore, and no need to move the mouse to select the output and copy it anymore. Except xclip, there is also a similar program called xsel, google it if you are interested in.

The homepage of xclip:

It’s very to install xclip via apt-get under Debian / Ubuntu based GNU/Linux distros or via pkgng under FreeBSD:

So how to use it?

If you want to copy something to clipboard, just pipe to xclip like this:

Now you can paste it as usual.

If you want to show something from clipboard, just call xclip to output:

xclip will output to standard output (stdout), so you can pipe or redirect the result to other utility and do some works you want.