Introduction
A.tar.gz files are compressed archives. It is a file that stores other files in a safe place. You can generate tar archives and carry out many modifications with the tar application. Tar can be used, for instance, on previously produced archives to extract files, add relevant files, upgrade new files, or list existing files that were originally saved. With the help of the gzip or bzip2 programs on Unix operating systems, an archive can include a large number of files, directories, and subfolders.
To unzip files using Linux command line you’ll want to add the highly effective gzip compression. For this, open a command-line terminal and type the following commands to open and extract with a .tar.gz file.
Through the use of pipes, Tar could send its output to nearby devices, folders, or other applications. It can additionally access distant devices or data (as archives). In essence, tar.gz is the result of two distinct processes. Since it can’t perform compression on its own, Tar essentially does nothing more than bundle several files together.
In this tutorial, you’ll discover how to unzip a tar.gz file in Linux or extract files from tar.gz files.
Ways to Extract/Unzip tar.gz Files in Linux
To reduce storage and bandwidth usage while downloading, tar.gz files combine many compressed files into a single file. Often called a tarball, the.tar file serves as portable storage space for other extracted files in Linux. Gzip, a widely used compression tool, is indicated by the .gz portion of the extension.
Extract Files Using the gzip utility
By design, Gzip extracts the file to the current working directory. In this instance, the file can be found in the Documents directory.
We’ve used the file test.txt in the example below. Otherwise, use the filename of the compressed file.
On your terminal window, type the following command to gzip Linux test.txt to compress a file type.
If you want to make sure the file has to get compressed after zipping it, type the command ls. The result confirms that the file’s extension has to be changed to .gz.
Gunzip is a command that can be used to decompress files:
gunzip test.txt
Examine the file extension once more using the ls command.
If you want to compress all the.txt files in a specific directory, type:
gzip *.txt
A wildcard character is represented by the symbol * and denotes “any number of any characters.” Every single one of the filenames ending in.txt would be compatible with this command.
Other file formats including gzip.txt,.jpg, and.doc can also get compressed using this method.
The system creates a compressed version of each file when gzip gets applied to multiple files all at once. This could also quickly fill up a database. However, there’s a second method to manage different files separately.
Also Read: 14 Tar Command in Linux (with Examples)
The tar utility
Combining a.tar file and a.gz file creates a tar.gz file. That is a compressed archive file that has multiple more files inside of it.
These files can be unzipped in Linux the same way as any other zip file:
tar documents.tar.gz
The standard command is tar, which gives you four available options:
- x- directs tar to extract the components from the compressed file.
- V stands for verbose, and even to list the documents it is extracting.
- Z – directs tar to decompress the files. Without doing so, you would have a folder containing a lot of compressed files.
- F – instructs Tar to operate with the specified filename.
When extracting a.tar file, input the following to list its contents:
tar documents.tar.gz
Use the following unzip command in Linux to tell tar where to place the unzipped files after they get extracted:
tar -xvzf documents.tar.gz /home/user/destination
Follow this Linux unzip command line to generate a tar.gz file:
tar -cvzf documents.tar.gz /Documents
The whole contents of the /home/user/Documents directory get compressed into a separate file called documents.tar.gz, similar to what the tar function does. The -z option directs tar to compress the files, according to the way it functions.
Utilize the following command to include several files in a tar file:
tar -cvf documents.tar /Documents
A single file entitled documents.tar gets created that contains everything in your Documents folder. The following describes how the options -cvf operate:
- C – Establish a new archive.
- V is for verbose, which means it displays the files it contains.
- The file’s name gets specified by f.
Use the commands below to extract the files in Linux from a.tar file:
tar -xvf documents.tar
All components in the documents.tar file get extracted and listed by this command. It instructs tar to obtain the files using the -x option.
Moreover, you can construct a tar.gz archive using xargs and then use the search command to add files to it.
Conclusion
Tar archives were originally used to store files on magnetic tape. This usage gave the name of the term “Tar,” which refers to tape archiver. Under Unix-like operating systems, the tar command can produce and handle archive documents in.tar.gz format. It is highly helpful for combining several files into a single archive file.
In the interests of working with tar.gz files, this post shows the correct way to utilize the tar and gzip tools individually and in combination. Now that you’re prepared, you can extract as well as unzip any tar.gz file in Linux.