Search code examples
bashsshtarbzip2

Extract a compressed directory using tar/bzip2 over SSH to local computer


I'd like to extract and uncompress (tar/bzip2) a compressed directory on a remote machine and save the directory and all its contents to my local computer without having to connect back into my local machine from the remote one. How can I do this over SSH? The tar file doesn't need to be stored on the remote machine, only on the local machine. I have tried:

ssh remotehost.somewhere.com "tar xf mydirectory.tar.bz2 | bzip2 -c " > mylocaldirectory


Solution

  • What flows through pipe is but a stream of bytes, so you don't "pipe" a directory.

    I suppose the archive exists on remote machine. This command extract a remote archive to local directory:

    ssh HOST "cat mydirectory.tar.bz2" | tar xj -C mylocaldirectory