Trying to do something like (in pseudo-unix):

scp -r <pwd> [email protected]:~/<dirname of toplevel>

In other words, I'm trying to copy the current directory I'm in locally (and the contents) over to remote while sticking the very last path segment from "pwd" commands output onto /home/user/<here> in the remote.

I'm shaky in my unix commands so I figured I'd ask vs. experiment this time to avoid damage

  • Why doesn’t scp -r . user@remote: do what you want?
    – sjy
    Feb 15, 2019 at 22:26

1 Answer 1

$ scp -pr "$(pwd)" [email protected]:"$(basename $(pwd) )/"
  • You can probably simplify this with scp -pr $(pwd) [email protected]: -- I think it'll automatically create the same-named directory. Feb 15, 2019 at 21:22
  • pwd shows the entire path. Probably not the intended effect.
    – DopeGhoti
    Feb 15, 2019 at 21:23
  • I agree, pwd does return the entire path, but scp doesn't try to recreate the entire path on the remote size, just the last element of the path (at least with my experimentation). Feb 15, 2019 at 21:25
  • thank you, it will still get me far enough without 'awk/sed'
    – Brandon J
    Feb 15, 2019 at 21:25
  • If the current working directory has spaces in its name this command still throws errors: extra arguments to basename and, even with "$(basename "$(pwd)")" a cryptic "scp: ambiguous target" — because quoting locally a remote path is not enough, quotes should also be sent to the remote host, e.g. scp -pr "$(pwd)" user@remote_host:"'""$(basename "$(pwd)")""'". But, actually, the simpler scp -pr "$(pwd)" user@remote_host: seems to just work.
    – fra-san
    Feb 16, 2019 at 11:15

You must log in to answer this question.

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