2

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

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

6 Comments

Good point, but I need the bzip2 to run on the remote machine, and then save the resulting files to my local machine
ssh HOST "bzcat mydirectory.tar.bz2" | tar x -C mylocaldirectory then.
Many thanks for your quick responses! I'm afraid I haven't been clear enough in my problem, allow me to clarify: I need to perform the extraction and decompression remotely, so both tar and bzip2 must run on remote machine. I only want to save the resulting directory (with all its contained files and subdirectories) to my local machine.
I'm afraid pipe itself can't handle directories. We archive files into binary streams, often with tar. Can I ask the reason of this full-remote limitation or decision?
After studying your suggestion again, I was able to solve the problem by piping the stream of bytes to bzip2, the solution that worked: ssh HOST "cat mydirectory.tar.bz2 | bzip2 -cd" | tar xj -C mylocaldirectory
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.