Skip to content

Using ssh to copy a directory tree from one host to another

From the source host:cd to the parent directory
Use the following command:

tar cf - sourcedir | ssh username@destination "cd destdirparent && tar xf -"

where:
sourcedir is the directory to copy
username is your username on the remote (destination) host
destdirparent is the parent directory on the remote (destination) host

One Comment

  1. Andrew S wrote:

    If your tar is GNUish you can save on the ‘cd’ with the C flag.

    e.g.

    tar cf – sourcedir | ssh username@destination tar xfC – destdirparent

    Tuesday, December 4, 2007 at 9:42 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*