From the command line to your clipboard and vice versa

Found a neat trick the other day via github.com, in their instructions for copying public keys. pbcopy (pasteboard copy) on mac OSX is a command that puts it's input into the clipboard so you can paste the output anywhere.

In this example the output of ls -la is now available to be pasted from your clipboard:

muffin@shiva $ls -la | pbcopy

Rather awesomely the reverse is also available it's called pbpaste. If you copy something to your clipboard you can then make use of it in the terminal with the pbpaste command. In other words pbpaste just sends the contents of your clipboard to stdout.

This example for the mac writes out the clipboard to the file, index.html: