Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
I think you got the title wrong. – Ignacio Vazquez-Abrams Apr 5 '12 at 3:31

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.

share|improve this answer

If you enable X forwarding then xclip can do this.

xclip -i -selection clipboard somefile
share|improve this answer

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .