How can I copy the output from a remote command into the local clipboard?

Posted by cwd on Super User See other posts from Super User or by cwd
Published on 2012-03-27T20:39:56Z Indexed on 2012/03/28 17:35 UTC
Read the original article Hit count: 259

Filed under:
|
|
|
|

I use iTerm2 as my terminal client in Mac OS X. On the local system I can use pbcopy and pbpaste to transfer data between the system clipboard and the terminal, but of course this doesn't work when you're ssh'ed to another machine.

Is there some way which I can take the result of a command and copy it to the clipboard automatically? Perhaps an applescript to grab the text on the iTerm windows, then get the next to last line?

For instance, if I wanted to copy the current working directory:

Picture-48.png

I run pwd, then use the mouse to select the text, and then press command + c.

Is there any better / faster / automatic way of doing this? I'm not looking for a bulletproof solution that would work for every command (eg: might not work when there is a huge scrollback) - I'm just looking for something to make this task that I do quite often a little less tedious.

Update

I'm looking into using screen to do this, but I'm still not sure if it is possible.

© Super User or respective owner

Related posts about linux

Related posts about ssh