How can I copy the output from a remote command into the local clipboard?
Well, I just tried this and it works:
echo "foo" | tee | ssh [email protected] pbcopy
Notes:
- I'm using
echo "foo"
as a stand-in for the command whose output you want to copy to yourssh
client machine. - I'm using
tee
so you can see it right in your terminal window instead of having it all swallowed up by thessh
command. - By giving
ssh
a command to run, it will send thestdin
thatssh
received to that command on that other host, and then immediately return.
You could probably alias it to something simpler to type. And be sure to use ssh
keys instead of password-based authentication to save yourself having to retype your password. Update: And you can use SSH Agent Forwarding so you don't have to put credentials to access your local machine on the remote box.
(NB: I'm not sure how well pbcopy/pbpaste work when you only have an ssh/tty/shell session and no Mac OS X GUI context. I think the pasteboard is a NeXTStep/Cocoa/Aqua/GUI concept, not necessarily something that exits at the Unix layer without the GUI layer.)
When I first came up with this it seemed hackish, but the more I play around with it the more I like it.