Table of Contents

What is a Tarball (tar.gz file, untar) and example on how to use the tar utility?

About

A tarball (tar.gz file) is a compressed tar archive.

Extract

tar -zxvf my.tar.gz
tar -xvf my.tar.gz

Extract one descendant file in the current directory

When a file is delivered in a tar file, it's generally in a subdirectory that indicate the version of the application.

Example for postgres_exporter.tar.gz if you unzip/untar it, you will get

postgres_exporter-0.15.0.linux-amd64/
postgres_exporter-0.15.0.linux-amd64/LICENSE
postgres_exporter-0.15.0.linux-amd64/postgres_exporter
postgres_exporter-0.15.0.linux-amd64/NOTICE

To extract the file postgres_exporter-0.15.0.linux-amd64/postgres_exporter in the current directory, you would execute:

tar -xzvf postgres_exporter.tar.gz \
  --strip-components=1 \ # delete the first path part
  --no-anchored \ # search the file name without taking the directory into account
  postgres_exporter