Pipe commands/output directly into your clipboard

Feb 18th, 2012 | By | Category: Linux / Freebsd

Ah, I had this thought today while running cat on a php file that it would really be nice if, instead of catting the file and then selecting the output in terminal, scrolling up, all the way up and copying it, I could just run cat on a file and have the output go directly to my clipboard.  Well this is linux baby so OF COURSE you can do that because it just makes a whole lotta fricken sense.

I needed to go and installed a little program called ‘xclip’ and after that all I had to do was type: cat file.php | xclip and guess what’s sitting in my secondary clipboard? Ooh yea, the bloody contents of file.php.

The funny thing is that by default the input should go into my primary clipboard(ctrl+v) but it goes into my secondary clipboard instead(middle mouse-button).  Anyways, to get around that all I need to do is type: cat file.php | xclip -selection c  and it ends up in the primary clipboard.

Either way, this is definitely one of the damned coolest things I’ve discovered in linux for a while!  Yay for efficiency!

Tags: , , , , , , ,

One Comment to “Pipe commands/output directly into your clipboard”

  1. BiSScuiTT says:

    Too awesome! This is my new favourite thing!

    Also, for even more fun, if you have X session forwarding over SSH setup and working, you can use xclip on a remote machine to add to your local clipboard.

    This is going to save me heaps of time!

Leave a Comment