6

I work on a remote machine through ssh. I have a very large text file there (approx. 500 lines) which I usually need to modify, then copy the contents of that file and paste it in my local browser. The way I usually do this is cat filename and then select/copy the ssh output. That takes a lot of time.

I was wondering if there is a utility that will put the remote file's contents in my local clipboard.

3

Try ssh pipes. Here's and example that works with OS X (Mountain Lion) (for Linux, adjust the cli clipboard program accordingly):

From the remote ssh machine, run:

$ cat /dir/file.txt | ssh user@localMachine pbcopy

You can use this functionality in remote vim editors by using ssh certificates for authorization and adding the following to vimrc on the remote machine:

vmap <C-c> y:call system("ssh user@localMachine pbcopy", getreg("\""))

Control-C in the remote editor should now copy to the local clipboard.

2

Personally, I'd open the remote file locally through e.g. Vim's SCP mode:

vim scp://uname@host/myfile

then edit and just copy it from Vim (e.g. by gg"*yG).

Alternatively you can use sshfs and the local editor of your choice.

1

If you enable X forwarding then xclip can do this.

xclip -i -selection clipboard somefile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.