What is the difference between Tar and Gzip ? Details with example
I too had this doubt! what is the difference between “tar” and “zip”. The answer is quit simple rather than the confusion. We all are very familiar about the word “.tar.gz”, it’s very common when we download something from internet. The extension “.tar.gz” is not a single file extension, it’s a combination of commonly using two technologies to combine and compress files together. That means “.tar.gz” is simply the combination of “.tar” and “.gz”.
The “tar” is a file archiving technique which combine multiple file into single file archive. It’s very useful when you want to transfer some files from one server/machine to another. Combining multiple files using the “tar” is helpful to upload and transfer files simply. We already discussed the usage and possibilities of tar command in Unix.
Gzip is file compression technique used to compress files which has large size. By using this file compression technique, we can simply reduce the file size before sending/transferring it from source to destination. We can also decompress the compressed file at the destination.
How to compress files using Gzip?
As a Unix admin, you can use the command “zip” and “gunzip” to compress and decompress files respectively. Here I am illustrating a simple example of the same.
Test file name is test.txt
To compress file to smaller:
# zip test.txt
After executing this command, the file size will reduce and will add the extension .gz to the file. Use the command “guzip” to decompress the file.
# gunzip test.txt.gz
File extension will come back to its original 🙂
See the file size and format variations in the above attached example.
How to create an archive using tar?
We have already discussed this in detail in one of our previous post, here I list the basic commands to create an archive and extract it. >> tar command in Linux with example <<
Create an archive using tar.
# tar -cvf archive.tar file1.txt file3.txt
Here the files file1 and file2 will combine together and formed the file archive.tar, you can use the tar command with switch -x to extract file from the archive created.
# tar -xvf archive.tar
Here we goes to the extension “.tar.gz”. Yes, there is an option in tar command to compress the files by using additional switches like “-z”, “-j” for Gzip and Bzip respectively.
# tar -zcf file.tar.gz file2.txt file1.txt
# tar -jcf file.tar.bz file2.txt file1.txt
We can conclude as:
>> Tar is a file archiving technology which combine multiple files to a single file archive.
>> Gzip is a compression methord to redusethe file size.
>> .tar.gz means the combination of tar and gzip to compress and combine files.