List of content you will read in this article:
What is TAR?
TAR is an abbreviation for Tape ARchive. This command was primarily developed to fulfill the purpose of creating archives and storing the files on magnetic tape. Hence, the name Tape Archive.
The tar command helps you to generate several tar archives as it converts as many files as you want into archives. When we talk about the tar command, it can be brought into use in ample ways. You can use it to add files to the archive, delete files, or extract tar archives. The list is pretty long.
Being a techie, it is highly evident that you are already familiar with the .tar.gz files.
These files are commonly known as ‘tarballs’. They are used by Linux, macOS, or even Windows users for backups or data archival.
Now, there are various methods to compress tar files. One of the most used methods to compress a file is Gzip. Moreover, whenever you compress the tar archive with gzip, it ends with .tar.gz or .tgz extension.
Besides, if you are a Windows user, you may need to download the 7zip tool to extract the tar.gz files. A lot of such third-party applications are also available in the market. They do come with a drawback, that is, they do not work every time.
In this article, we are going to make you familiar with some ways to extract tar.gz archives in both Linux and Windows.
How to extract tar.gz file in Linux?
It is a simple process to extract the tar.gz file in Linux.
Before that, take a look at the meaning of these symbols:
x: This option is used to extract the files.
v: It means Verbose. It helps to list the files in the archive.
z: This is used to uncompress a file.
f: You can easily keep a name for the file by using this option.
To start with, if the file is compressed by a gzip compressor, you can apply the following command:
tar -xzf filename.tar.gz
In this command, filename.tar.gz is the name of the archive that you want to unpack. Additionally, if you want to seek more information about the files, you may use the -v option. Here, -v stands for Verbose. Take a look:
tar -xvzf filename.tar.gz
Easy, right? But somehow if your work impedes and you don’t get the desired results, follow another method.
How to extract files without gzip?
Use the following command:
tar -xf filename.tar.gz
And your work is done.
Moving on, if you wish to uncompress the tar.gz file in a directory, follow this command:
$ tar xvzf file.tar.gz -C /path/to/somedirectory
Here, -C is used to mention the particular path to store the file.
The next command is to extract a .doc file from the .tar.gz file. Take a look at the command below:
$ tar -xvzf file.tar.gz test.doc
Moving on, if you want to extract some particular files from a tar.gz file, use this command:
tar -xf archive.tar.gz file1 file2
This command is specifically used for files. If you want to extract some directories, use the following command:
tar -xf archive.tar.gz dir1 dir2
Moreover, to print the name of the files for extraction using the tar command, use this command:
tar -xvf archive.tar.gz
Sometimes you get an error message like this:
tar -xf archive.tar.gz README
It implies that the files that you want to extract don't exist.
Moving on, if you want to list the content of your tar.gz file, then use the below-mentioned command:
tar -tf archive.tar.gz
Here is the output.
Well, these were some of the commands to extract tar.gz files in Linux.
The next segment talks to you about extracting tar.gz files in Windows. Let’s see how!
How to extract tar.gz files in Windows?
If you are a Windows user, here are a few steps for you to follow so that you can easily extract
- Tap on Start on your Windows
- Now, go to the Command Prompt and click right. Choose Run as Administrator option
- Enter this command in the command prompt: tar -xvzf C:\PATH\TO\FILE\FILE-NAME.tar.gz -C C:\PATH\TO\FOLDER\EXTRACTION
You can add any desired path to store your files. After you press enter, all the files will be extracted to the path that you mention.
If you do not wish to use the command line method, don’t worry. There is another solution. You can simply head towards the File manager and click right on the file that you wish to extract. Choose the Extract option.
That’s it. You are done.
In a nutshell, tar.gz files or tarballs are used to archive data and backups. It is necessary to decompress and extract these files in order to get your work going.
There are specific ways and methods to conclude your task through various steps and commands.
As you have seen, this article assists you to extract the tar.gz file, whether you are a user of Linux or Windows.
We hope that the information provided in this article helps you in the best way possible.
Keep learning. Keep evolving.