How to create and unzip zip, tar, tar.gz and tar.bz2 files under Linux

  

For many years, data compression has been very useful for us. Whether it's a zip file for images sent in emails or a compressed data file on a server, we can make it easier or more efficient to save disk space. Some compression formats sometimes allow us to compress files at a rate of 60% (or even higher). Below I will show you how to use these commands to compress files or directories under Linux. We will learn the basic usage of compression formats such as zip, tar, tar.gz and tar.bz2. These are the compression formats commonly used in Linux.

Before we explore these usages, I would like to share with you the experience of using different compression formats. Of course, what I am talking about here is just some of the usages. Apart from what I have mentioned, they have more places to discuss. I have realized that I need to understand two or three compression formats in order to use them better. The zip format is the first format to understand. Because it has actually become the standard choice for compressed files, and it can be used on Windows. I often use zip format to compress files that need to be shared with windows users. If you just share it with a linux user or a Mac user, I prefer to choose the tar.gz format.

ZIP zip is probably the most widely used document compression format. Its biggest advantage is its use on different operating system platforms such as Linux, Windows and Mac OS. The downside is that the supported compression ratio is not very high, and tar.gz and tar.gz2 do very well in terms of compression ratio. Gossip less, let's get to the point: We can compress a directory with the following command:
# zip -r archive_name.zip directory_to_compress

Here's how to extract a zip file:
# unzip archive_name.zip

TAR Tar is a very extensive document packaging format used in Linux. The advantage is that it only consumes very little CPU and time to package files. It is just a packaging tool and is not responsible for compression. Here's how to package a directory:
# tar -cvf archive_name.tar directory_to_compress

How to unpack:
# tar -xvf archive_name.tar.gz

The above unpacking command will unpack the documentation Open under the current directory. Of course, you can also use this command to pinch the path to unpack:
# tar -xvf archive_name.tar -C /tmp/extract_here/

TAR.GZ This format is the compression format I use the most. . It does not take up too much CPU when compressing, and it can get a very good compression ratio. Use the following format to compress a directory:
# tar -zcvf archive_name.tar.gz directory_to_compress

Unzip:
# tar -zxvf archive_name.tar.gz

The above unpack command will The document will be unpacked under the current directory. Of course, you can also use this command to pinch the path to unpack:
# tar -zxvf archive_name.tar.gz -C /tmp/extract_here/

TAR.BZ2 This compression format is what we mentioned The compression ratio is the best in all modes. Of course, this means that it takes more CPU and time than the previous method. This is how you use tar.bz2 for compression.

Reprinted from: http://blog.tangjianwei.com/2009/01/02/how-to-create-and-extract-zip-tar-targz-and-tarbz2-files-in-linux /

Copyright © Windows knowledge All Rights Reserved