I have a path which is:


and I'd like to scp four/five/

recursively to another machine at the location:


so that it appears like:


My current path is /one/two/three when I do:

scp -r four/five user@bla:/zero/

but on the destination machine it looks like:


instead of:


(if rsync is simpler, happy to use that).


2 Answers 2


Local operations like mv four/five /zero/ or cp -r four/five /zero/ don't create /zero/four/ and hardly anyone expects them to. For this reason what you call "not expected" is rather expected to me.

tar stores the supplied path (see this question). Make use of this fact.

cd /one/two/three \
&& tar -cf - four/five | ssh user@bla '
   cd /zero && tar -xf -
  • But you can make cp do that with --parents. Jun 3, 2020 at 20:38

scp behaves the same as mv and cp here. Assuming four contains other directories besides five you can run

ssh user@bla 'mkdir -p /zero/four'
(cd four && scp -r five user@bla:/zero/four/)

to just copy five.

  • mkdir -p avoids an error message if the directory already exists
  • (cd ... ) runs the line in a subshell so you don't need to cd out of four afterwards

You must log in to answer this question.

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