Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Many, many times a day, I find myself wanting to copy one or two files from ~/src/some/path/or/other and ~/src/some/different/path on my local machine, to /srv/www/some/path/or/other and /srv/www/some/different/path respectively on a testing host. The two paths are identical after ~/src and /srv/www respectively -- although obviously I usually omit the filename on the second arg to scp, which I currently use.

Problem is, I quite often fat finger the scp invokation entirely and copy the file to the wrong directory, or overwrite a different file because tab complete manages to outsmart me. I could rsync my whole local tree to the server over ssh, but I sometimes don't want to upload the whole thing just yet -- just a specific file.

I guess what I want is simple CLI tool which will let me do (maybe with a little config) the moral equivalent of:

jkg5150@dev-laptop:~/src/myproject$ funkytool path/to/file another/path/another-file mydevhost.mycompany.com

...and have file copied to mydevhost.mycompany.com:/srv/www/myproject/path/to/, and another-file copied to mydevhost.mycompany.com:/srv/www/myproject/another/path/.

Surely there's a trick I'm missing -- or should I just write one?

share|improve this question
    
Do you grok bash (or even sh)? This looks like a fairly simple shell script. –  Scott Jan 25 '13 at 0:21
    
Sure; I just wondered if there was an existing tool before I rolled my own. –  James Green Jan 26 '13 at 19:00

1 Answer 1

up vote 2 down vote accepted

Use rsync with the -R option. From the rsync(1) man page:

   -R, --relative
          Use  relative  paths. This means that the full path names speci‐
          fied on the command line are sent to the server rather than just
          the  last  parts  of  the filenames. This is particularly useful
          when you want to send several different directories at the  same
          time. For example, if you used this command:

             rsync -av /foo/bar/baz.c remote:/tmp/

          ...  this would create a file named baz.c in /tmp/ on the remote
          machine. If instead you used

             rsync -avR /foo/bar/baz.c remote:/tmp/

          then a file named /tmp/foo/bar/baz.c would  be  created  on  the
          remote machine, preserving its full path.  These extra path ele‐
          ments are called "implied directories" (i.e. the "foo"  and  the
          "foo/bar" directories in the above example).
share|improve this answer
    
This appears to be exactly what I was looking for -- thanks! –  James Green Jan 30 '13 at 19:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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