How can i duplicate a directory on my server via ssh?

cp -r directory_name destination
  -R, -r, --recursive
          copy directories recursively

... or maybe you want to exchange folders between hosts. Than you should use rsync

rsync -vaz --rsh="ssh -l username" ~/bk targetHost:~/test
  • you mean rsync -vaz ~/bk username@targetHost:~/test – Justin Feb 6 '10 at 20:39

tar also would be a candidate for this job:

tar cf - . | ssh user@host 'cd /$destination && tar xBf -'
  • While a little more complicated, tar is awesome for when you need the files to exactly match. I tend to use this for cloning filesystems or uncompressed backups. – Scott Pack Feb 6 '10 at 17:50
  • 1
    using tar over ssh like that is also a number of times faster than scp or rsync when dealing with a lot of tiny files. – Justin Feb 6 '10 at 20:40

You could do this with either rsync or scp, both of which go over ssh.

scp -rp directory remotehost:/path/to/directory

rsync -azv -e ssh directory/ remotehost:/path/to/directory
  • ... and I forgot about scp. – Mad_Dud Feb 6 '10 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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