What are Tar and Gz? Difference between them.

While working in Linux you would have seen files downloaded from the internet ended up with either “.tar” or “.tar.gz”. Now, what are these extensions? Both of these imply the file is in Archived format that could contain a single file or multiple folders but still if both the Tar and Gz produce archive files then what is the difference between them? In this article, we will explain exactly what these formats are and how to use them.

What Is Tar?

Tar got its name from “Tape Archive” because earlier it was used to write data to sequential I/O devices. However, with time it is now used to combine multiple files and create a large single file also known as an archive just like the ZIP file format.

Usually, the files are archived using “Tape Archive” ending with a suffix of “.tar”, that’s why we call this tool Tar or sometimes Tarball (especially when the file is compressed).

Also, the packing and unpacking of the archives created by “Tar” is quick and easy to perform because no compression was done by it. In short, Tar will archive all the files into one but without compressing them.

What Is Tar.gz (or Gzip Compressed Tar File)?

A “tarball” is a common term for a tar archive, compressed using Gzip (.gz). Files ending with the extension “.tar.gz” or “tgz” are commonly referred to as “gzipped tar files” or just plain ‘tarballs’ for short.

As compared to the standard Tar archives that ended up with .tar extension, compressed gzipped files are smaller in size than the uncompressed ones. When the file uses GZ compression then instead of .tar it will have .tar.gz extension. And by just seeing the extensions we can easily identify whether the file is compressed or not.

Using GZ compression large-size files become easier to transfer over networks such as the internet or storage media such as CDs and DVDs which typically only support small capacity disks or limited network data speeds due to bandwidth limitations like DSL connections…

Additionally, gzipped tarballs often have higher retention ratios, meaning they keep more of their original contents compared to non-compressed archiving systems like zip packages where some information may be lost due to compression algorithms used on certain types of data structures (like audio streams and video codecs).

In one line– .GZ is only an extension of the Tar file which refers that the user has compressed the file to create an archive.

How To Use Tar And Tarballs?

Both Tar and Tar.gz uses the same command-line utility therefore users can easily use the same type of command syntax for archiving a file.

For example:

To extract an existing archive with/without compression:

tar -xvf filename.extension

Where “filename ” is the name of a file or files that you have with extensions (.tar..tar.gz,.tgz etc).

When working with archives you can also specify exactly which directory(ies) you want to be extracted by giving it/them as parameters directly after “-xvf”, like so:

tar -xvf filename.extension -C /path-to-somedir

Additionally, if you plan on creating your own tar/targz archives in the future, here’s how you do that too:

Without compressing

tar -cvf my.tar file-name

With Compression

tar -czvf my.tar.gz file-name

my.tar is the name of the output archive in which we want to save the file. Whereas, replace “file-name” with the file in your current directory that you want to be archived.

  • tar – It is a command line tool for Archiving
  • czvf – In this, -c means “Creates a new archive”; -v is to show the process of archiving performed by the tar; -f is to specify the file. And -z is for compression and to use GZ.

You can know more about how to use the Tar command in Linux, here.

Here is a comparison table between tar and gz:

File typeArchiveCompressed
UsageBundling multiple files into a single archive fileCompressing a single file to reduce its size
ExamplesCreating backup files, distributing multiple files as a single entityReducing the size of a large log file, compressing a single text file for email transmission


Difference between Tar and tar.gz?

The file uses Tar as its extension is a normal archived file created using TAR tool whereas TAR.GZ file means a compressed Archived using TAR and Gzip.

Can tar files be deleted?

Yes, we can delete Tar files form our computer or else if you want to delete from particular file from the archive then that is possible as well.

To remove the Tar file from your Linux system.

sudo rm -r filename.extension for example sudo rm -r myfile.tar

Whereas to remove the content from the inside of Tar archive file use –delete option.
For example: If you Tar file name is my.tar and you want to delete a file/folder inside it name games, then the command will be:

tar --delete --file=my.tar games

Is tar same as zip?

No, Tar is not same as ZIP, although both are used for archiving files and folders but there method to deal with files are different. For example – Zip by default compress the file but Tar doesn’t.

Why tar is used in Linux?

Tar is the default in-built tool in Linux systems used to create a archive file by comprising a single or multiple folder or files. If you don’t have it on your Linux then can easily be installed using the default package manager.

How do I tar to another folder?

To extract the Tar file into any other folder instead of current directory you have to specify the path of the folder and -C option in the command. For example: If I have a file name mylinux.tar and to extract in Downloads directory, the command will be like this- tar -xvf mylinux.tar -C ~/Downloads

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.