Moving Files with Secure Shell

May 8, 2014

I had a large CVS repository which I wanted to move between two unix boxes. I would normally just created a tar on the source machine, then transferred that tar file using sftp. This wasn't possible in this case as there wasn't enough disk space.

It is possible to tar to stdout, then pipe stdout through ssh where it can be unpacked on the remote machine. This removes the need for disk space on the source machine.

$ tar cf - * | ssh user@remote.machine '(cd /destination; tar xvf - )'
  • Create a tar file of everything in the current directory (*), and pipe it to stdout (-).
  • Then pipe that stdout to a remote machine.
  • Once there, cd to the destination directory and untar it

Tags: ssh tar cvs