What is the difference between Tar and Gzip ? Details with example

本文详细解释了文件归档技术tar和文件压缩技术gzip的区别及使用方法。介绍了如何使用tar将多个文件打包成一个档案文件,并利用gzip减小文件大小。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 ?

zip

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.
Examples:
For gzip,

# tar -zcf file.tar.gz file2.txt file1.txt

For bzip,

# 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.

That’s it.

Related Links:
1, Differences between POP3 and IMAP protocol
2, tar command usages with examples

转载于:https://www.cnblogs.com/Bruce3555/p/5468430.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值