pbcopy / pbpaste in OS X

I came across a nifty utility in OS X that allows you to copy / paste data to/from the clipboard without having to select text and command+c/command+v

Michael-MacBook-Pro:~
(michael)> echo foo | pbcopy

Michael-MacBook-Pro:~
(michael)> pbpaste
foo

Thats kind of neat.  What about connecting to a remote machine, executing some command, and then having that output in the clipboard of your local machine?

Michael-MacBook-Pro:~
(michael)> ssh somehost.com uptime | pbcopy

Michael-MacBook-Pro:~
(michael)> pbpaste
5:26pm  up 64 day(s),  8:30,  4 users,  load average: 0.04, 0.04, 0.04

5 Comments

matty  on February 13th, 2009

Dude, that is sweet!

hubb  on February 13th, 2009

awesome !

z0mbix  on February 13th, 2009

I’ve been after something like this for years. Thanks!

esaruoho  on October 10th, 2011

I’d absolutely love it if there was some way of re-formatting a pbpaste result ( such as
Macintosh HD:Users:esaruoho:folder actions:sceneorg_renoise:24017.html to (url/)24017.html :)
and then copying it via pbcopy..

John  on January 2nd, 2012

esaruoho: this is unfinished — i did not bother writing the regex, but you can output pbpaste through a filter ; pbcopy it and then pbpaste the changed string:

prompt$ pbpaste | sed -e “s/REGEX/URL$1/g” | pbcopy ; pbpaste

Leave a Comment