How to download an archive and extract it without saving the archive to disk?

You can do it by telling wget to output its payload to stdout (with flag -O-) and supress its own output (with flag -q):

wget -qO- your_link_here | tar xvz -

To specify a target directory:

wget -qO- your_link_here | tar xvz - -C /target/directory

Update

If you happen to have GNU tar

wget -qO- your_link_here | tar --transform 's/^dbt2-0.37.50.3/dbt2/' -xvz

should allow you to do it all in one step.

-q quiet

-O - output to stdout


Another option is to use curl which writes to stdout by default:

curl -s some_url | tar xvz -C /tmp

This oneliner does the trick:

tar xvzf -C /tmp/ < <(wget -q -O - http://foo.com/myfile.tar.gz)

short explanation: the right side in the parenthesis is executed first (-q tells wget to do it quietly, -O - is used to write the output to stdout).

Then we create a named pipe using the process substitution operator from Bash <( to create a named pipe. This way we create a temporary file descriptor and then direct the contents of that descriptor to tar using the < file redirection operator.

Tags:

Shell

Pipe

Wget

Tar