Pipe stuff from bash to your clipboard

I have been using GNU/Linux for over 10 years now and it seems like the more I learn the more I realize how little I know. This week at work we wrote a bad ass bash script that does all sorts of magical stuff and this got me thinking “What else is possible”.

One of my favorite things about GNU and Linux is that whenever you ask yourself “Is it possible to do $X in bash” the answer is usually yes.

For example, I write a lot of these blog posts in vim and it can be a pain to copy the text out to paste back into WP. I wondered if I could just cat everything to my clipboard, and it turns out this is super easy. As usual Stack Overflow has all of the answers.

It turns out there is a program called xclip that lets you take anything from bash and pipe it into your clipboard.

In debian you can install it easily by running:

apt-get install xclip

I set up a bash alias called clip in my ~/.bashrc file that looks like this: alias clip="xclip -selection c"

Now I can cat, grep, ls, echo, etc and pipe it into clip, with the output going directly into my clipboard. For example, the next time you want to email someone a list of all of the chinese hackers that are trying to break into your server you can just do this:

cat /var/log/auth.log | clip

The output will be in your clipboard and you can paste it into your email. This changes everything.

If you made it this far, you should probably follow me on twitter. 🙂

This entry was posted in Hacking and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *