How to Extract a Tar.gz File in Ubuntu

The Archive Extraction Vector

When downloading source code, complex software packages, or server backups in a Linux environment, you will rarely encounter standard .zip files. Instead, the Linux ecosystem heavily relies on the “tarball” format (files ending in .tar.gz). This format first bundles multiple files together using the tar utility, and then heavily compresses that bundle using gzip. If you are operating a headless Ubuntu server, you cannot double-click these files to extract them; you must utilize specific command-line syntax to reverse the compression and unpacking process.

How to Extract a Tar.gz File

You must use the core tar command coupled with a precise sequence of flags to instruct the system on exactly how to handle the archive.

1. Open your terminal application or connect to your server via SSH.
2. Use the cd command to navigate to the directory where your downloaded archive is located (e.g., cd /home/user/downloads/).
3. To extract the file into your current directory, execute the following command, replacing filename.tar.gz with your actual file:

tar -xzvf filename.tar.gz

Here is the breakdown of the flags you must use:
* -x (Extract): Tells the utility you are unpacking an archive, not creating one.
* -z (Gzip): Instructs the utility to push the file through the gzip decompression algorithm first.
* -v (Verbose): Forces the terminal to output the name of every single file as it is extracted, providing visual confirmation that the process is working.
* -f (File): This flag must always be last. It specifies that the very next word you type is the name of the target file.

The terminal will instantly spit out a long list of files and drop the newly extracted folder directly into your current working directory.

Get the best tech tips delivered straight to your inbox.

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