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,
.tgz extension is used. This tutorial shows how to extract tar gz file in Linux.
tar command can be used for extracting tar archive files. A syntax to extract
tar xf filename.tar.gz
- 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
.tar.gz file can be extracted in a specific directory by providing
sudo tar xf backup.tar.gz -C /tmp