Extract Tar Gz File in Linux

Extract Tar Gz File in Linux

A tar is an archive file (.tar) for storing collection of files and directories. Various algorithms can be used to compress a tar archive file. The gzip algorithm is one of the most popular. By convention, when a tar archive file is compressed with gzip, .tar.gz or .tgz extension is used. This tutorial shows how to extract tar gz file in Linux.

The tar command can be used for extracting tar archive files. A syntax to extract .tar.gz file:

tar xf filename.tar.gz

Adding - before the options (xf) is optional for tar command. Compression algorithm is automatically detected. Used options:

  • x - specifies to extract an archive file.
  • f - specifies filename of archive file.

For example, the following command allows to extract backup.tar.gz file to current working directory:

tar xf backup.tar.gz

The .tar.gz file can be extracted in a specific directory by providing -C option:

sudo tar xf backup.tar.gz -C /tmp

Leave a Comment

Cancel reply

Your email address will not be published.