Compress a directory using tar/gz over SSH to local computer?

You can do it with an ssh command, just tell tar to create the archive on its standard output:

ssh remote.example.com 'cd /path/to/directory && tar -cf - foo | gzip -9' >foo.tgz

Another approach, which is more convenient if you want to do a lot of file manipulations on the other machine but is overkill for a one-shot archive creation, is to mount the remote machine's filesystem with SSHFS (a FUSE filesystem). You should enable compression at the SSH level.

mkdir ~/net/remote.example.com
sshfs -C remote.example.com:/ ~/net/remote.example.com
tar -czf foo.tgz -C ~/net/remote.example.com/path/to/directory foo

Tags:

Bash

Ssh

Tar