Sending data to the clipboard from command line

In several occasions I find myself catting some file and then having to select the entire text with the mouse. If I want to keep my hands on the keyboard, I have to do a vim file, ggVG, “+y, :q.

Well, I found a way to do it faster and nicer simply by piping to the clipboard, thanks to xclip.

To use it, just install it and configure an alias in your .bashrc file, as follows:

$ sudo apt-get install xclip
$ alias clipboard='xclip -selection clipboard'

Then, when you need to do something like configuring your SSH key in GitHub, you just:

$ cat ~/.ssh/id_rsa.pub | clipboard

Thanks to Brian Racer for this snippet!

Leave a comment