Intelligenteres SCP, das einen Teil des lokalen Pfads dupliziert

Intelligenteres SCP, das einen Teil des lokalen Pfads dupliziert

Viele, viele Male am Tag möchte ich ein oder zwei Dateien von ~/src/some/path/or/otherund ~/src/some/different/pathauf meinem lokalen Rechner auf /srv/www/some/path/or/otherbzw. /srv/www/some/different/pathauf einen Testhost kopieren. Die beiden Pfade sind nach ~/src bzw. /srv/www identisch – obwohl ich den Dateinamen im zweiten Argument von scp, das ich derzeit verwende, normalerweise weglasse.

Das Problem ist, dass ich den SCP-Aufruf häufig komplett verpasse und die Datei in das falsche Verzeichnis kopiere oder eine andere Datei überschreibe, weil Tab Complete es schafft, mich auszutricksen. Ich könnte meinen gesamten lokalen Baum per SSH mit dem Server synchronisieren, aber manchmal möchte ich noch nicht alles hochladen – nur eine bestimmte Datei.

Ich schätze, was ich möchte, ist ein einfaches CLI-Tool, mit dem ich (vielleicht mit ein wenig Konfiguration) das moralische Äquivalent von Folgendem tun kann:

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

... und habe filenach kopiert mydevhost.mycompany.com:/srv/www/myproject/path/to/, und another-filenach kopiert mydevhost.mycompany.com:/srv/www/myproject/another/path/.

Es gibt bestimmt einen Trick, den ich übersehe – oder soll ich einfach einen aufschreiben?

Antwort1

Verwenden Sie rsync mit der -ROption. Aus der rsync(1)Manpage:

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

verwandte Informationen