tar
"GNU 'tar' saves many files together into a single tape or disk archive, and can restore individual files from the archive." - man tar
on linux
"tar - manipulate tape archives" - man tar
on macOS
Examples
Deal with leading slash quirks
Some tar archives have a leading ./
stored for every filename:
$ curl -fsSL https://github.com/vectordotdev/vector/releases/download/v0.20.1/vector-0.20.1-x86_64-unknown-linux-gnu.tar.gz | tar -tzf -
./vector-x86_64-unknown-linux-gnu/
./vector-x86_64-unknown-linux-gnu/README.md
./vector-x86_64-unknown-linux-gnu/bin/
./vector-x86_64-unknown-linux-gnu/bin/vector
and some do not
$ curl -fsSL "https://get.helm.sh/helm-v3.8.2-linux-amd64.tar.gz" | tar -tzf -
linux-amd64/
linux-amd64/helm
linux-amd64/LICENSE
linux-amd64/README.md
This alters the syntax when you want to extract a single file. You need to give the exact filename seen in tar -t
to extract a single file. If you want to never have to deal with that leading ./
, you can add --no-anchored
danielh@cs-462709900404-default:~/temp/2022-04-20$ curl -fsSL https://github.com/vectordotdev/vector/releases/download/v0.20.1/vector-0.20.1-x86_64-unknown-linux-gnu.tar.gz | tar -tzf - vector-x86_64-unknown-linux-gnu/bin/
tar: vector-x86_64-unknown-linux-gnu/bin: Not found in archive
tar: Exiting with failure status due to previous errors
danielh@cs-462709900404-default:~/temp/2022-04-20$ curl -fsSL https://github.com/vectordotdev/vector/releases/download/v0.20.1/vector-0.20.1-x86_64-unknown-linux-gnu.tar.gz | tar -tzf - --no-anchored vector-x86_64-unknown-linux-gnu/bin/
./vector-x86_64-unknown-linux-gnu/bin/
./vector-x86_64-unknown-linux-gnu/bin/vector