linuxize.com Open in urlscan Pro
2606:4700:20::681a:f0  Public Scan

URL: https://linuxize.com/post/how-to-extract-unzip-tar-gz-file/
Submission: On February 16 via manual from CA — Scanned from CA

Form analysis 1 forms found in the DOM

Name: mc-embedded-subscribe-formPOST https://linuxize.us17.list-manage.com/subscribe/post?u=35cd4cd9d021c25c3dd7cabfd&id=9cfa4c89de

<form action="https://linuxize.us17.list-manage.com/subscribe/post?u=35cd4cd9d021c25c3dd7cabfd&amp;id=9cfa4c89de" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="pt-8" novalidate="">
  <div class="flex flex-col sm:flex-row items-center justify-between w-full max-w-sm mx-auto mb-2"><input type="email" name="EMAIL" placeholder="Your email..." aria-label="email"
      class="appearance-none block w-full bg-white text-gray-800 border hover:border-gray-700 rounded py-3 px-4 mb-3 sm:mb-0">
    <input type="text" name="b_35cd4cd9d021c25c3dd7cabfd_9cfa4c89de" tabindex="-1" class="hidden">
    <button type="submit" name="subscribe" class="bg-indigo-700 tracking-wide hover:bg-indigo-800 text-white py-3 px-4 sm:ml-4 w-full sm:w-auto rounded">
      <span class="text-center">Subscribe</span></button>
  </div>
  <p class="w-full max-w-sm mx-auto my-0 text-sm">We’ll never share your email address or spam you.</p>
</form>

Text Content

Linuxize
Ubuntu Centos Debian Commands Series Donate



HOW TO EXTRACT (UNZIP) TAR GZ FILE

Updated  Sep 24, 2019

•

4 min read


report this ad

Contents

 * Extracting tar.gz File
 * Extracting Specific Files from a tar.gz File
 * Extracting tar.gz File from stdin
 * Listing tar.gz file
 * Conclusion

Share:




If you are roaming the open-source world, chances are you encounter .tar.gz
files on a regular basis. Open-source packages are generally available to
download in .tar.gz and .zip formats.

The tar command is used to create tar archives by converting a group of files
into an archive. It supports a vast range of compression programs such as gzip,
bzip2, lzip, lzma, lzop, xz and compress. Tar was originally designed for
creating archives to store files on magnetic tape which is why it has its name
“Tape ARchive”.

Gzip is the most popular algorithm for compressing tar files. By convention, the
name of a tar archive compressed with gzip should end with either .tar.gz or
.tgz.

In short, a file that ends in .tar.gz is a .tar archive compressed with gzip.

The tar command can also be used to extract tar archives, display a list of the
files included in the archive, add additional files to an existing archive, as
well as various other kinds of operations.

In this tutorial, we will show you how to extract (or unzip) tar.gz and tgz
archives.


EXTRACTING TAR.GZ FILE #

Most Linux distributions and macOS comes with tar command pre-installed by
default.

To extract a tar.gz file, use the --extract (-x) option and specify the archive
file name after the f option:

tar -xf archive.tar.gzCopy

The tar command will auto-detect compression type and will extract the archive.
The same command can be used to extract tar archives compressed with other
algorithms such as .tar.bz2 .

If you are a Desktop user and the command-line is not your thing you can use
your File manager. To extract (unzip) a tar.gz file simply right-click on the
file you want to extract and select “Extract”. Windows users will need a tool
named 7zip to extract tar.gz files.

The -v option will make the tar command more visible and print the names of the
files being extracted on the terminal.

tar -xvf archive.tar.gzCopy

By default, tar will extract the archive contents in the current working
directory . Use the --directory (-C) to extract archive files in a specific
directory:

For example, to extract the archive contents to the /home/linuxize/files
directory, you can use:

tar -xf archive.tar.gz -C /home/linuxize/filesCopy


EXTRACTING SPECIFIC FILES FROM A TAR.GZ FILE #

To extract a specific file(s) from a tar.gz file, append a space-separated list
of file names to be extracted after the archive name:

tar -xf archive.tar.gz file1 file2Copy

When extracting files, you must provide their exact names including the path, as
printed by --list (-t).

Extracting one or more directories from an archive is the same as extracting
files:

tar -xf archive.tar.gz dir1 dir2Copy

If you try to extract a file that doesn’t exist, an error message similar to the
following will be displayed:

tar -xf archive.tar.gz READMECopy

tar: README: Not found in archive
tar: Exiting with failure status due to previous errors
Copy

You can also extract files from a tar.gz file based on a wildcard pattern, by
using the --wildcards option and quoting the pattern to prevent the shell from
interpreting it.

For example, to extract files whose names end in .js (Javascript files), you
would use:





tar -xf archive.tar.gz --wildcards '*.js'Copy


EXTRACTING TAR.GZ FILE FROM STDIN #

If you are extracting a compressed tar.gz file by reading the archive from stdin
(usually through a pipe), you need to specify the decompression option. The
option that tells tar to read the archives through gzip is -z.

In the following example we are downloading the Blender sources using the wget
command and pipe its output to the tar command:

wget -c https://download.blender.org/source/blender-2.80.tar.gz -O - | sudo tar -xzCopy

If you don’t specify a decompression option, tar will indicate which option you
should use:

tar: Archive is compressed. Use -z option
tar: Error is not recoverable: exiting now
Copy


LISTING TAR.GZ FILE #

To list the content of a tar.gz file, use the --list (-t) option:

tar -tf archive.tar.gzCopy

The output will look something like this:

file1file2file3CopyCopyCopy

If you add the --verbose (-v) option, tar will print more information, such as
owner, file size, timestamp ..etc:

tar -tvf archive.tar.gzCopy

-rw-r--r-- linuxize/users       0 2019-02-15 01:19 file1-rw-r--r-- linuxize/users       0 2019-02-15 01:19 file2-rw-r--r-- linuxize/users       0 2019-02-15 01:19 file3CopyCopyCopy


CONCLUSION #

tar.gz file is a Tar archive compressed with Gzip. To extract a tar.gz file, use
the tar -xf command followed by the archive name.

If you have any questions, please leave a comment below.

tar terminal

Related Tutorials

 * How to Extract (Unzip) Tar Bz2 File
 * How to Create Tar Gz File
 * How to Extract (Unzip) tar.xz File
 * Tar Command in Linux (Create and Extract Archives)
 * Understanding the /etc/shadow File
 * Basic Linux Commands
 * Bash: Append to File



report this ad

If you like our content, please consider buying us a coffee.
Thank you for your support!

Buy me a coffee

Sign up to our newsletter and get our latest tutorials and news straight to your
mailbox.

Subscribe

We’ll never share your email address or spam you.


RELATED ARTICLES

Sep 24, 2019


HOW TO EXTRACT (UNZIP) TAR BZ2 FILE



Jul 22, 2020


HOW TO CREATE TAR GZ FILE



Mar 4, 2020


HOW TO EXTRACT (UNZIP) TAR.XZ FILE


Write a comment

Please enable JavaScript to view the comments powered by Disqus.
ESC

© 2022 Linuxize.com Privacy Policy Terms Contact Advertise on Linuxize



ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_~x