How to Extract 'tar.gz' Files in Linux

A simple command decompresses and expands tarballs

Crane lifting compressed trash at garbage dump
Hero Images / Getty Images

A file with the extension .gz has been compressed using the gzip command. A file with the extension .tar has been tarballed into a single archive. Thus, a .tar.gz file is a zipped tarball.

Unpacking the Compressed Tarball

Decompress the gzip file and extract the files from the tar file using a single command as follows:

tar -xvzf FILENAME.tar.gz

Listing the Contents of a 'tar.gz' File

Be careful about extracting tar.gz files that you receive from other people or from download links as they may either deliberately or inadvertently harm your system.

View the contents of a tar file using the following syntax:

tar -tzf images.tar.gz

The above command will show you the names and locations of the files that will be extracted. Be wary of tarbombing, or expanding tarballs that throw a lot of files in various places around your filesystem in ways that might sneak a malicious edit into your core system-config files.