로컬 경로의 일부를 복제하는 더 똑똑한 scp

로컬 경로의 일부를 복제하는 더 똑똑한 scp

하루에 여러 번 로컬 컴퓨터에서 하나 또는 두 개의 파일을 테스트 호스트로 ~/src/some/path/or/other복사 하고 싶습니다 . 두 경로는 ~/src 및 /srv/www 이후 각각 동일합니다. 물론 일반적으로 현재 사용하는 scp에 대한 두 번째 인수의 파일 이름을 생략합니다.~/src/some/different/path/srv/www/some/path/or/other/srv/www/some/different/path

문제는 내가 scp 호출을 완전히 파악하고 파일을 잘못된 디렉토리에 복사하거나 탭 완료가 나를 능가하기 때문에 다른 파일을 덮어쓰는 경우가 많다는 것입니다. SSH를 통해 전체 로컬 트리를 서버에 재동기화할 수 있지만 때로는 전체 내용을 아직 업로드하고 싶지 않은 경우가 있습니다. 특정 파일만 업로드하는 것입니다.

내가 원하는 것은 다음과 같은 도덕적인 작업을 수행할 수 있는 간단한 CLI 도구인 것 같습니다.

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

...그리고 file에 복사 했고 mydevhost.mycompany.com:/srv/www/myproject/path/to/, another-file에 복사했습니다 mydevhost.mycompany.com:/srv/www/myproject/another/path/.

확실히 제가 놓친 트릭이 있습니다. 아니면 하나만 작성해야 할까요?

답변1

옵션 과 함께 rsync를 사용하십시오 -R. 매뉴얼 페이지 에서 rsync(1):

   -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).

관련 정보