7

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?

2 Answers 2

11

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
2
  • Thanks. This removes the 'x' attribute so I have to run chmod +x /usr/local/bin/helm after that but it does the trick. Jul 18, 2017 at 21:25
  • I improved the answer, so that it doesn't lose the file mode. Jul 18, 2017 at 21:37
3

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
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .