Extract TAR files over SSH

Instead of copying a large tar file over ssh then extracting, take care of the whole process with one command:

PUSH METHOD:

cat  tarfile | ssh –C user@remotehost “(cd targetdirectory && tar –xf -)”

This will stream the tarfile over a compressed ssl tunnel and the other side will only extract if the target directory exists. The “cd targetdirectory” piece I used as a good prevention to blowing files all over an undesired/unexpected location.

PULL METHOD:

ssh -C user@remotehost”cd sourcedirectory; tar -cvf – dir_or_file> outputfile

This is the opposite method, obviously.  Please note, the output of the SSH needs to be redirected to an output file.

One Response to “Extract TAR files over SSH”

  1. jimsander says:

    Couldn’t agree more. I appreciate the feedback, I’ll look at cleaning it up.

Leave a Reply

You must be logged in to post a comment.