April 27, 2012 0

Send text to clipboard in linux terminal

What we'd like to do is have a quick way of sending text to the clipboard from terminal in linux. We can accomplish this with pipes and xclip. We'll install and configure xclip and then review the proper usage.

First we install xclip:

sudo apt-get install xclip

Next we want to configure an alias for xclip so that the arguments "-selection c" are used every time we call xclip. This ensures that the text is piped (copied) into the correct clipboard. This command will place the alias specification into the .bashrc file in our home directory.

echo "alias xclip=\"xclip -selection c\"" >> ~/.bashrc

Now we need to load our new .bashrc settings into the current window or open a new window.

source ~/.bashrc

Now we can use xclip as follows:

uptime | xclip

In my case I like being able to copy my public keys directly from file into github, so I use it like so:

cat ~/.ssh/id_rsa.pub | xclip

Tags:

Dedicated Server Hosting by Hivelocity