copying directories between servers compressed

~ 2 min read

Often you just need to copy a directory between one server and another, and as a lot of them will be text files compression will really help speed things up. Well here’s a couple of shell commands to help get the job done.

Copy a directory and its children to a remote system as tar file over ssh

First make your current working directory the directory you want to copy files from, replace some user@somehost.com with the target username and domain name you want to copy the tar file to of the current directory and it’s sub-dircetories, changing /home/someDirectory to be the remote directory you want the tar file placed in.

tar -cvf - . | ssh someuser@somehost.com "(cd /home/someDirectory && cat - > tmp.tar )"

Copy a directory and its children to a remote system over ssh and unpack it

First make your current working directory the directory you want to copy files from, replace some user@somehost.com with the target username and domain name you want to copy the current directory and it’s sub-directories and files to, changing /home/someDirectory to be the remote directory you want the local directory and sub-directories placed in.

tar -cvf - * | ssh someuser@somehost.com "(cd /home/someDirectory && tar -xvf - )"

all posts →