How to create and decompress ZIP, tar, tar.gzand tar.bz2 files in Linux

Source: Internet
Author: User
Tags decompress zip

 

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

Data Compression has been very useful for us over the years. Whether it is a zip file used for sending images in an email or compressing data files on the server, we can make the download easier or more effective to save disk space. Some compression formats sometimes allow us to compress files at a rate of 60% (or even higher. Next I will show you how to use these commands to compress files or directories in Linux. We will learn the basic usage of zip, tar, tar.gzand tar.bz2 compression formats. These are common compression formats in Linux.

Before exploring these usage, I would like to share with you the experience on using different compression formats. Of course, I am only talking about some of the usage here. Apart from what I 've talked about, they still have more things worth exploring. I have realized that I need to know two or three compression formats to better use them. ZIP format is the first format to be understood. Because it has actually become the standard choice for compressing files, and it can also be used on Windows. I often use zip to compress files that need to be shared to Windows users. If you only share it with the linuxlinuxuser to access macusers, I prefer to select the tar.gz format.

Zip
Zip may be the most commonly used File compression format. It is used on different operating system platforms, such as Linux, windows, and Mac OS. The compression rate is not very high, and tar.gzand tar.gz 2 are very good in terms of compression rate. Let's start with the question:
We can use the following command to compress a directory:

# Zip-r archive_name.zip directory_to_compress

Below is a zip file:

# Unzip archive_name.zip

Tar
Tar is a widely used document packaging format in Linux. Its advantage is that it only consumes a very small amount of CPU and time to package files. It is only a packaging tool and is not responsible for compression. The following shows how to package a directory:

# Tar-CVF archive_name.tar directory_to_compress

How to unpack:

# Tar-xvf archive_name.tar.gz

The preceding command unpacks the document in the current directory. Of course, you can also use this command to hold the path for unpacking:

# Tar-xvf archive_name.tar-C/tmp/extract_here/

Tar. GZ
This format is the most commonly used compression format. It does not occupy too much CPU during compression, and can obtain an ideal compression rate. Use the following format to compress a directory:

# Tar-zcvf archive_name.tar.gz directory_to_compress

Decompress:

# Tar-zxvf archive_name.tar.gz

The preceding command unpacks the document in the current directory. Of course, you can also use this command to hold the path for unpacking:

# Tar-zxvf archive_name.tar.gz-C/tmp/extract_here/

Tar. bz2
This compression format is the best compression ratio among all the methods we mentioned. Of course, this means that it takes more CPU and time than the previous method. For example, you can use tar.bz2 for compression.

# Tar-jcvf archive_name.tar.bz2 directory_to_compress

The preceding command unpacks the document in the current directory. Of course, you can also use this command to hold the path for unpacking:

# Tar-jxvf archive_name.tar.bz2-C/tmp/extract_here/

Data Compression is very useful, especially for backup. Therefore, you should now consider using the compression method you learned here in your backup script to back up your basic rule file to reduce the size of your backup file.

After a while, you will realize that there will be a balance between the compression ratio and CPU usage time. You also need to learn how to weigh when you need a fast but low compression ratio, when do you need a compression method with a high compression rate but a high CPU point, then you can avoid unnecessary space and time.

Source: http://www.simplehelp.net/2008/12/15/how-to-create-and-extract-zip-tar-targz-and-tarbz2-files-in-linux/
Note:
The original author misunderstood a concept. The tar command does not support compression. It is just a package command. The suffix is just a recognized public suffix, and it is not a compression format (gzip and Bzip2 are actually implemented for compression, that's not the case .), In many cases, tar.gz is also abbreviated as tgz.
In the translation, most of them respect the original author, But I modified it when explaining the tar function.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.