Table of Contents

About

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

Extract

  • If in zip format
tar -zxvf my.tar.gz
  • Otherwise
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