4

My goal is to get the helm binary from helm-v2.5.0-linux-amd64.tar.gz into my /usr/local/bin in as few steps as possible. The challenge is that the .tar.gz file contains the binary in a linux-amd64 subdirectory.

So when I do this:

$ wget -P /tmp https://storage.googleapis.com/kubernetes-helm/helm-v2.5.0-linux-amd64.tar.gz
$ tar -xzvf /tmp/helm-v2.5.0-linux-amd64.tar.gz -C /usr/local/bin linux-amd64/helm

I end up with /usr/local/bin/linux-amd64/helm instead of /usr/local/bin/linux-amd64/helm.

Is there a tar parameter I am missing or do I need to include some mv & cleanup steps?

5

You need to use --strip-components=NUMBER:

--strip-components=NUMBER
          Strip NUMBER leading components from file names on extraction.

which means that your command should look like this:

tar -xzvf /tmp/helm-v2.5.0-linux-amd64.tar.gz -C /usr/local/bin --strip-components=1 linux-amd64/helm
  • Thanks. This removes the 'x' attribute so I have to run chmod +x /usr/local/bin/helm after that but it does the trick. – Borek Bernard Jul 18 '17 at 21:25
  • I improved the answer, so that it doesn't lose the file mode. – Strahinja Kustudic Jul 18 '17 at 21:37
2

Another approach, piping wget straight into tar, and using the transform param.

wget -O- https://storage.googleapis.com/kubernetes-helm/helm-v2.5.0-linux-amd64.tar.gz | tar --transform 's!linux-amd64!/usr/local/bin!' -Pxzf - linux-amd64/helm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.