One-liner for downloading and extracting a tar.gz

I’m not the typical Linux one-linerd, but there are some that I find very useful.

Why execute 3 commands to download a tar.gz file, extract its contents and delete the archive, when actually there’s no need to store the archive physically (you only care about its contents) and you could save one command in the process?

So that’s why I love
wget -O- <url> | tar zxv
I tried the same for zip files but it doesn’t work. According to man unzip:

Archives read from standard input are not yet supported, except with funzip (and then only the first member of the archive can be extracted).

If anyone knows a workaround, it will be very appreciated!


One thought on “One-liner for downloading and extracting a tar.gz

  1. I don’t think it is very technically feasible to do this for zip files. Even if you were to implement it, it could require a large amount of ram to process, as the entire zip would have to be contained in ram.

    You may be asking why that is not the case with tar and gzip. It’s very simple, zip requires random access to the file. Meaning it can’t just read from the input and provide a direct output from it. It must look up in the directory and scan different portions for the file, even to output a single file.

    So the entire thing must be accessible before you can start decompressing files.

    Random Access == fail for piping (in general, as I said, it’s possible, just not practical)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s