Learn how to extract tar files in Linux: Untar gz files and more. When working with Linux or Unix systems, you’ll often encounter files compressed in formats like tar, tar.gz, or .tgz. These compression methods are popular for packaging software and other downloadable content. Knowing how to extract or untar files becomes essential for effectively managing and using their contents.
What is the Tar Command?
Tar stands for "tape archive" and is GNU software originally developed for backing up data to tape drives. It is still used today for consolidating and compressing data. The tar command is used in Unix and Linux systems to bundle multiple files and directories into a single archive file, simplifying the management, storage, and transfer of large sets of files. Archives created with tar are typically saved with a .tar extension and can also be compressed to save space, resulting in files like .tar.gz or .tar.bz2.
What is the Untar Command in Linux?
In Linux, the term "untar command" isn't a standalone command. Instead, it commonly refers to the process of extracting, unzipping, or uncompressing tar and tar.gz files from a tar archive. The actual command used for this purpose is the tar command, combined with specific extraction options or arguments, enabling you to untar files, as we will cover next.
Untar Command Options
Here is a breakdown of what each tar command option or argument does when this command is used to unzip tar, tar.gz, and tgz files:
Untar Linux Option | What the Untar Command Option does |
---|---|
-x | Extract files from an archive. |
-z | Use gzip compression to extract the archive. |
-v | Be verbose, display the progress and file list. |
-f | Specifies the input file (e.g., .tgz file). |
-C /myfolder | Change to the specified directory before extracting files. |
The following tar examples cover how to untar both popular formats and extract the contents of the compressed archive to a different directory.
How to Unzip a tar file in Linux or Unix
You can unzip tar files in Linux or Unix by using the tar command along with the -xzvf options. Here's how:
- Open a terminal; ctrl+alt+t
- From the terminal, change to the directory where your .tar file has been downloaded.
cd ~/directory_path
- To extract or tar unzip the file to the current directory, type the following command,
(Making sure to replacefile_name.tar
with the actual filename)tar -xvf file_name.tar
You can also specify a different directory to extract to using the -C parameter and path to the directory as follows:
tar -C /myfolder -xvf file_name.tar
Extracting a tar gz file in Linux or Unix
To extract tar gz files in Linux or Unix from an open terminal:
- Change directory to where your .tar.gz file is located,
cd ~/directory_path
- To extract the contents of the tar.gz file to the current directory,
(replacingfile_name.tar.gz
with the actual name of your file), use the following command:tar -zxvf file_name.tar.gz
Note that this process also works to decompress and extract the contents of a .tgz file:
tar -xzvf file_name.tgz
Or to extract to another directory, type the following, changing /myfolder to the path you want to extract to:
tar -C /myfolder -zxvf file_name.tar.gz
There you have it. A few simple commands are all it takes to untar, unzip or extract tar gz files from within running Linux or Unix operating environments. Hopefully this has helped you decompress, unpack and extract those compressed tar and tar gz files you downloaded from the internet. If you are looking for additional helpful solutions, you might want to check out this right mouse click open files as root article.