Extract Tar Gz Files in Linux Command Line

This tutorial intends to teach you how to Extract Tar Gz (tar.gz) Files in the Linux Command Line. In the Linux operating system, a tar.gz file is a compressed archive format. It is used to compress multiple files and directories into a single file. It has two parts: Tar and Gz which means:

Tar: This is a tool that creates archive files which are known as tarballs. It will collect files into a single file.

Gz: It is the compression tool that reduces the file size. It will compress the tar archive into a tar.gz or gzipped tarball file.

Purpose of Using Tar GZ Files in Linux

The purpose of using tar.gz files in Linux devices in two parts:

Bundle Files and Directories in Linux: As we said, Tar will collect multiple files and directories into a single file. This will help you to manage and transfer your files easier.

Compression: While Tar collects files and directories, Gzip reduces the size of the tar file by compressing it. It will help you to save storage and transfer your data faster.

Quickly Learn To Extract Tar Gz Files in Linux Command Line

At this point, we assume that you have a tar.gz file and you want to extract it. Now you can follow the steps below to see how you can do it.

Extracting a tar.gz File in Linux from CLI

Before beginning the extracting process, you must have the tar command line tool on your Linux OS. To install tar on Linux, you can use:

Debian / Ubuntu:

sudo apt install tar

RHEL / AlmaLinux / Fedora / Rocky Linux:

sudo dnf install tar -y

Next, you can use the following tar syntax to extract your tar.gz file:

tar -xvzf filename.tar.gz

Let’s see the meaning of the options in the above command:

  • -x: Extract files from an archive.
  • -z: Use gzip decompression.
  • -v: Verbose mode (optional, for displaying progress).
  • -f: Specify the archive file name.

This command will extract the file into your current directory. If you want to extract the file to another directory, you need to use the -C option:

tar -xvzf filename.tar.gz -C /path/to/directory

This will extract your file to your specified directory.

Conclusion

At this point, you have learned that tar.gz files are used in Linux for packaging software distributions, backups, and transferring or archiving large files and directories. If you have a tar.gz file, you can simply use the tar command with the required options to extract it.

Hope you enjoy using it. Also, you may like to read the following articles:

Transfer Files from the Linux Server to the Local Machine

Using Fasd in Linux for Quick Access to Files & Directories

Fix unknown filesystem type NTFS error in Linux

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!