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

Source: Internet
Author: User

Over the years, data compression has been very useful for us. Whether it's a zip file for a picture sent in a message 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 ratio 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'm talking about here is just some of the usage, and there's more to it than I've talked about. I have realized that I need to know two or three compression formats in order to better use them. The ZIP format is the first format you need to know. Because it's actually a standard choice for compressed files, and it can be used on Windows as well. I often compress files that need to be shared with Windows users in a zip format. If it's shared with Linux users or Mac users, I prefer to choose the tar.gz format.

Zip
Zip is probably the most used document compression format. Its greatest advantage is in the use of different operating system platforms, such as Linux, Windows and Mac OS. The downside is that the compression ratios are not very high, and tar.gz and TAR.GZ2 are doing very well in terms of compression. Gossip less, let's get to the point:
We can compress a directory with the following commands:

# zip-r Archive_name.zip directory_to_compress

The following is if you unzip a zip document:

# Unzip Archive_name.zip

TAR
Tar is a very extensive document packaging format used in Linux. The advantage is that it consumes very little CPU and time to package files, he is just a packaging tool, not responsible for compression. Here's how to package a directory:

# TAR-CVF Archive_name.tar directory_to_compress

How to unpack the package:

# TAR-XVF Archive_name.tar.gz

This unpacking command will unlock the document under the current directory. Of course, you can also use this command to squeeze the path of the unpacking:

# TAR-XVF Archive_name.tar-c/tmp/extract_here/

TAR. GZ
This format is the most compressed format I have used. It does not take up too much CPU when compressing, and it can get a very ideal compression rate. Use the following format to compress a directory:

# TAR-ZCVF archive_name.tar.gz directory_to_compress

Unzip:

# TAR-ZXVF Archive_name.tar.gz

This unpacking command will unlock the document under the current directory. Of course, you can also use this command to squeeze the path of the unpacking:

# TAR-ZXVF Archive_name.tar.gz-c/tmp/extract_here/

TAR. BZ2
This compression format is the best compression rate in all of the ways we mentioned. This, of course, means that it consumes more CPU and time than the previous way. 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/

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

Related Article

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.