Tar/Gzip Hacks

· cyclicircuit's blog

A way to extract specific files from tar.gz archives in a single incantation

How to Extract Specific Files from .tar.gz files #

It recently came to my attention that a lot of software on Github is being distributed through their releases interface, specifically in .tar.gz archive files. This is a perfectly fine format, but tar has a reputation for being a rather obtuse program to remember.

As a result, I found myself wondering: Can I download a tar.gz file, pipe it into tar and only extract the one file I want, thus installing the uv binary by simply dropping it into /usr/local/bin. And the answer is yes! Apparently I can! It just took some looking through documentation and searching through Stack Overflow.

Here's the basic example:

1wget -c https://github.com/astral-sh/uv/releases/download/0.5.5/uv-x86_64-unknown-linux-gnu.tar.gz -O - | tar -zxv --strip-components 1 -C /usr/local/bin uv-x86_64-unknown-linux-gnu/uv;

So what's going on here?

The end result of this is that /usr/local/bin/uv will be present on your system (and usable).


References: