Back

OSX Command Line and the clipboard

OSX comes with a lot of little gems for developers that many are not aware of. Two that I recently learned about are pbcopy and pbpaste.

The first command, pbcopy, allows you to get something onto the clipboard from the command line. I find this very useful when I need to paste my ssh public key into a web form, for example. In order to get my key into the clipboard, I can just execute:

$ cat .ssh/id_rsa.pub | pbcopy

And like magic, my key is on my clipboard ready to be pasted into a web form or whatever.

The second command, pbpaste, just goes in the opposite direction and outputs whatever is on the clipboard. I have yet to find this one as useful, but it’s nice to have in the toolbox.

If you’re wondering why the commands start with “pb” instead of “cb”, apparently the clipboard is also known as the pasteboard. I had never heard that before.

Leave a Reply

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