How to Extract a .tar.gz File in the Linux Terminal

When downloading open-source software, custom fonts, or database backups on a Linux system, the files are almost always compressed into an archive ending in .tar.gz. Unlike Windows, which uses standard .zip files, Linux relies on a combination of the ‘tar’ utility (which bundles multiple files together into a single archive) and the ‘gzip’ utility (which compresses that archive to make the file size smaller). To extract these files in the terminal, you only need to memorize one simple command.

Using the ‘tar’ Command

You can unbundle and decompress the archive simultaneously using a specific combination of command flags.

  1. Open your terminal application.
  2. Navigate to the folder where your downloaded file is located (e.g., cd ~/Downloads).
  3. Type the following command, replacing the filename with your actual file:
    tar -xzf archive_name.tar.gz
  4. Press Enter.

The command will silently execute, and a new uncompressed folder containing all your files will instantly appear in the same directory.

Understanding the Flags

If you are wondering what those letters actually do, it is very straightforward:

  • -x: eXtract (tells the command you are taking files out, not putting them in).
  • -z: gZip (tells the command to decompress the gzip compression).
  • -f: File (tells the command that the very next word you type is the name of the archive).

If you prefer to actually see a live, scrolling list of every single file as it is being extracted out of the archive, you can simply add a v (for Verbose) to the flags, making the command: tar -xvzf archive_name.tar.gz.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.