Skip to content

Instantly share code, notes, and snippets.

@purplefish32
Created March 9, 2012 14:39
Show Gist options
  • Save purplefish32/2006776 to your computer and use it in GitHub Desktop.
Save purplefish32/2006776 to your computer and use it in GitHub Desktop.
Compress and copy via SSH using TAR
#Compress and copy via SSH using SCP and TAR
tar -czf - /some/file | ssh [email protected] tar -xzf - -C /destination
#Switch -c for tar creates an archive and -f which tells tar to send the new archive to stdout.
#The second tar command uses the -C switch which changes directory on the target host. It takes the input from stdin. The -x switch extracts the archive.
#The second way of doing the transfer over a network is with the -z option, which compresses the stream, decreasing time it will take to transfer over the network.
#Some people may ask why tar is used, this is great for large file trees, as it is just streaming the data from one host to another and not having to do intense operations with file trees.
#If using the -v (verbose) switch, be sure only to include it on the second tar command, otherwise you will see double output.
#Using tar and piping can also be a great way to transfer files locally to be sure that file permissions are kept correctly
#Source : http://www.crucialp.com/resources/tutorials/server-administration/how-to-copy-files-across-a-network-internet-in-unix-linux-redhat-debian-freebsd-scp-tar-rsync-secure-network-copy.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment