↑ ↓ select, Enter open, Esc close

Copy a directory to another server with tar over SSH

Caution: This command changes the system. Understand what it does before you run it.

Adjust the values, the command updates live
user@server
tar czf - -C /var/www/vhosts/example.com/httpdocs . | ssh webuser@neuserver.example.com "tar xzf - -C /var/www/vhosts/example.com/httpdocs"

Packs the contents of the source directory, sends the data stream through SSH and extracts it on the target. This saves space for an intermediate archive and is often faster than scp with many small files. The target directory must already exist.

Note: Files with the same name on the target are overwritten. For repeated syncs, rsync is the better choice.

Also searched as

  • tar over ssh copy directory
  • transfer website to new server
  • copy many small files over ssh fast

Related one-liners

All in SSH

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.