Preloader
Ubuntu
  • Estimated reading time: 1 Minute

How to extract the content of a tar.gz file in Ubuntu

TAR files are created by tar, the famous Unix-based utility to package files in a single file to distribute it or just for backup. The TAR file contains multiple files that are stored in an uncompressed format as well with the metadata of the archive. Once it has been packaged inside the TAR file, it's usually compressed using some algorithm, in this case the GNU Zip compression (that's why the file includes the .gz extension).

You will find distributables of many projects, utilities in this format, so after downloading it in your server or local environment, you may be wondering right now how to easily extract its content into the same directory or just store its content into another directory, that's why I will explain to you how to easily extract the content of this type of files easily.

Extract content of tar.gz

If you want to extract the content of the file to the same directory where the tar.gz file is located, you may use the following command:

tar -xvzf file.tar.gz

The -xvzf instruction can be broken down like this:

  • -x : Specifies the tar utility to extract the content from an archive.
  • -v : Specify to verbosely list all the files that are being extracted (output in the terminal).
  • -z : Specify that the content should be decompressed using the GZIP algorithm.
  • -f : This argument specifies the filename of the tar to work with. This must be specified as the last argument and the path should appear immediately after it.

And that's it! Alternatively, if you want to specify a custom directory where the content should be extracted, you can do it with the -C argument to specify tar to change the directory (so the package content will be unpacked there):

tar -xvzf file.tar.gz -C /var/www/some-directory

Happy coding ❤️!

Share:
Carlos Delgado

Carlos Delgado

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Related articles
How to install the latest version of Git in Ubuntu 20.04
26 Aug, 2022
  • Estimated reading time: 1 Minute
How to install aapanel in Ubuntu 20.04
14 Aug, 2022
  • Estimated reading time: 1 Minute
How to install Prometheus Node Exporter on Ubuntu 20.04
27 Mar, 2022
  • Estimated reading time: 4 Minutes
How to install Anaconda in Ubuntu 20.04
6 Nov, 2021
  • Estimated reading time: 3 Minutes
How to install Elasticsearch 7 in Ubuntu 20.04
29 Apr, 2021
  • Estimated reading time: 5 Minutes
Weekly trending
How Modern Crown Technology Makes Dental Visits Easier
6 Jun, 2026
  • Estimated reading time: 10 Minutes
The Technology Behind Smarter Boat Navigation Systems
6 Jun, 2026
  • Estimated reading time: 2 Minutes
The Future of Human Machine Interfaces Is Simpler Than Ever
6 Jun, 2026
  • Estimated reading time: 2 Minutes
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.