SBaronda.com a little place I like to call home.


Bash one-liner for download and extracting files from tarballs

Dec. 19, 2020

There are many different ways to accomplish extracting a tarball from the internet. In my case I wanted to extract helm binary from it's original tarball release.

I'm using tar 1.30 and wget 1.20.1 to do this.

First, do a test extraction to see what the file structure of the tarball looks like:

wget -qO- https://get.helm.sh/helm-v3.4.2-linux-amd64.tar.gz | tar tvfz -
drwxr-xr-x circleci/circleci 0 2020-12-09 10:21 linux-amd64/
-rwxr-xr-x circleci/circleci 41603072 2020-12-09 10:20 linux-amd64/helm
-rw-r--r-- circleci/circleci     3341 2020-12-09 10:21 linux-amd64/README.md
-rw-r--r-- circleci/circleci    11373 2020-12-09 10:21 linux-amd64/LICENSE

Using --wildcards and --transform will allow you to only extract out the helm executable without the linux-amd64 folder.

After you find the target file you want to extract you can extract it via:

wget -qO- https://get.helm.sh/helm-v3.4.2-linux-amd64.tar.gz | \
    tar xvzf - -C /tmp/ --wildcards *helm --transform 's/^linux-amd64\///'

And you'll be left with:

ls -ld /tmp/helm 
-rwxr-xr-x 1 silas silas 41603072 Dec  9 10:20 /tmp/helm


comments powered by Disqus