Find best webhosting in chennai

Location

Chennai

Working Hours

09:00 AM to 07:00 PM ( Mon - Sat )

Phone Number

(+91) 9884800300

How to extract tar.gz files in Linux.

How to Extract tar.gz files?

In this article you will know how to extract tar.gz files. A “.tar” file is a collection of files compressed into a single file or archive. Short for “Tape ARchive,” the name “TAR” is a throwback to when files were stored on magnetic tape drives.

Thankfully, you don’t need to be a 1960s computer technician to use and extract .tar files – nor do modern .tar files even have anything to do with old computers.

Just like the more familiar .zip files, .tar files compress large files into a single package, making it easier to store and send them through email, servers, and so on. As a result, it has become a common file extension for many open-source software packages and other resources.

But with .zip being the easier of the two to use, why use .tar in the first place? The next section shows how .tar comes with a few extra features that make it the better compression format for certain files and applications.

.tar vs .zip

Where most operating systems make it easy to extract and create .zip files, the same can’t really be said for .tar files — at least not in ways that are easy to notice.

Of course, that’s not to say .tar files are some kind of “lesser” format than .zip. Rather, they both accomplish the same task (file compression) in the same way. Here’s a breakdown of how it all works.

  • A .tar file is a collection of uncompressed files, sometimes known as a tarball. Since .tar doesn’t compress anything, it requires a separate compression utility for compression. As we see later, one popular compression utility is gzip, which compresses a .tar into a .tar.gz file.
  • A .zip file is a collection of compressed files. Rather than use a separate compression utility to compress the entire collection, .zip automatically compresses each file within the collection.

By now, you’ve probably noticed the major difference between .tar and .zip files: compression methods.

Where .zip files consist of many individually compressed files, .tar files are compressed as a single package, leaving its files uncompressed. In other words, .zip files are a collection of compressed files, while .tar files are a compressed collection of files.

But does the compression method really matter, especially if both methods technically produce compressed files?

It depends. For sending and storing, both .zip and .tar.gz files allows you to send relatively large packages as a single file. However, there are some pretty major differences when it comes to accessing data within the files and the compression efficiency.

  • .zip files are more accessible — Since data in a .zip are compressed individually, they can also be accessed individually. By contrast, data in a .tar.gz is only accessible after extracting the entire file.
  • .tar.gz files are more space-efficient — Since .tar files are compressed as a single entity rather than a group of individually compressed files, compression utilities can group similarities between files and cut down on space. In other words, compressing files as a single group allows for more efficient compression methods, thereby saving space and reducing the overall size of the file.

If that’s not entirely clear, don’t worry. Technical details aside, all you need to remember is that .zip files are more accessible but less space-efficient, while .tar files are less accessible but more space-efficient. As a result, one isn’t necessarily better than the other — it’s all a matter of application.

How do I unzip a .tar.gz file in Linux terminal?

You can unzip most .tar.gz and other compressed .tar files using the tar utility.

To unzip a .tar.gz file in the Linux terminal, you can use the tar command:

For the simplest method, begin by opening the terminal (CTRL+ALT+T) and navigate to the directory of the .tar.gz file you want to unzip. Then enter the following command:

extract tar.gz files file to current working directory:

tar -xf filename.tar.gz

This command extracts (-x) the file (-f) specified (in this case, filename.tar.gz) to the current directory. Note that this command also works with other common compression formats such as .tar.bz2.

The tar command also comes with several other options. Like many Linux commands, one of these is a verbose output (-v) that prints the extracted files to the terminal window:

Extract tar.gz file to current working directory and print output:

tar -xvf filename.tar.gz

Extract tar.gz file to a different working directory:

tar -xf filename.tar.gz -C /home/user/files

Only extract specific files or directories from .tar.gz in Linux

The tar command also provides support for extracting only specific files or directories from a .tar.gz file. Simply add a space-separated list of the files you want to extract.

Extract file1 and directory1 from .tar.gz file to current working directory:

tar -xf filename.tar.gz file1 directory1

Note that this command will throw an error unless you specify the exact filename listed in the .tar file. As we cover more in the next section, you can verify file names by listing contents with the tar -tf filename.tar.gz command.

You can also use –wildcards to extract all files with a certain extension or name.

extract tar.gz files ending with “.txt” from .tar.gz file:

tar -xf filename.tar.gz --wildcards '*.txt'

List contents of .tar.gz file in Linux

It’s often useful to list the contents of a .tar.gz file without having to unzip the entire archive. The -list (-t) option outputs a list of filenames.

List contents of a .tar.gz file:

tar -tf filename.tar.gz

You can also add the verbose output option (-v) to provide detailed listings, including dates, securities/permissions, and more.

List detailed contents of a .tar.gz file:

tar -tvf filename.tar.gz

Many compression utilities also offer their own commands for listing the contents of compressed files. For example, gzip allows you to list the contents of a .gz file with the following command:

List detailed contents of a .gz file with gzip:

gzip -l filename

Zip and unzip .tar and .tar.gz in Linux with gzip

You can create your own compressed .tar files using compression utilities such as gzip. Gzip is one of the most popular and available options, especially since it comes built in to most Linux distributions and macOS.

In the terminal, navigate to the working directory of the .tar file you want to compress and simply enter the following command:

Compress .tar file with gzip:

gzip filename.tar

You can easily unzip the resulting .tar.gz file with the decompress (-d) option.

Decompress .tar.gz file with gzip:

gzip -d filename.tar

If you want to keep the original file after compression, there are two options. The first is the -k option, and the other uses the -c option to output the compressed file to a different file, preserving the original.

Compress .tar file and keep original copy:

gzip -c filename.tar

Compress .tar file and store as a different file:

gzip -c filename.tar > newfilename.tar.gz

Like the tar utility, gzip also allows you to zip and unzip multiple files or entire directories at a time.

Compress multiple files:

gzip file1 file2

Decompress multiple files:

gzip -d file1 file2

Compress all files in a directory:

gzip -r directory1

Decompress all files in a directory:

gzip -dr directory1

That’s it from the above commands you know how to extract tar.gz files. In order to remove or terminate cpanel account from command click here.