Archive, compress and send

You want to archive (tar), compress (gzip) and send (scp) a directory in one command? With Linux, it is possible:

tar cf - yourdir | gzip -9 -c | ssh -l root yourhost.example.com 'cat > /path/to/output.tar.gz'

What does it do?

tar cf - yourdir creates a uncompressed archive and writes it to standard out (stdout).

gzip -9 -c reads from standard in (stdin), compresses and writes to standard out.

ssh -l root yourhost.example.com 'cat > /path/to/output.tar.gz' takes the content from stdin and writes it to the defined file on the remote host.

And the crazy thing: It actually works. Weird shit.