Borderline ServerFault question, but I'm programming some shell scripts, so I'm trying here first 🙂
Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same. On OS X these commands are
pbcopy, pbpaste
Is there anyway to replicate this functionality while SSHed into another server? That is,
- I'm using Computer A.
- I open a terminal window
- I SSH to Computer B
- I run a command on Computer B
- The output of Computer B is redirected or automatically copied to Computer A's clipboard.
And yes, I know I could just (shudder) use my mouse to select the text from the command, but I've gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.
Code is useful, but general approaches are appreciated as well.
Best Answer
My favorite way is
ssh [remote-machine] "cat log.txt" | xclip -selection c
. This is most useful when you don't want to (or can't) ssh from remote to local.Edit: on Cygwin
ssh [remote-machine] "cat log.txt" > /dev/clipboard
.Edit: A helpful comment from nbren12: