Linux in the gzip command to use the detailed

Source: Internet
Author: User
Tags bz2 config

Gzip

A compression command that is more commonly used under Linux to compress a file into a compressed file with a. GZ ending

Preparatory work

[Root@localhost etc]# Cp/etc/man.config/tmp

[Root@localhost etc]# Cd/tmp

[Root@localhost tmp]# LL

Total 12

-rw-r--r--. 1 root root 2730 June 03:45 Chkconfig.txt

-rw-r--r--. 1 root root 4940 Aug 12:37 man.config

1. Compress man.config Files

[Root@localhost tmp]# gzip Man.config

[Root@localhost tmp]# LL

Total 8

-rw-r--r--. 1 root root 2730 June 03:45 Chkconfig.txt

-rw-r--r--. 1 root root 2184 Aug 12:37 man.config.gz

You can see the source file Man.config is not replaced by a compressed file that ends with. gz. Compared to the source file, you can find that the size does have a narrowing

2. Decompression man.config.gz

[Root@localhost tmp]# gzip-d man.config.gz

[Root@localhost tmp]# LL

Total 12

-rw-r--r--. 1 root root 2730 June 03:45 Chkconfig.txt

-rw-r--r--. 1 root root 4940 Aug 12:37 man.config

3. If you want to keep the source files, you can use the following command

[Root@localhost tmp]# gzip-c man.config >>man.config.gz

[Root@localhost tmp]# LL

Total 16

-rw-r--r--. 1 root root 2730 June 03:45 Chkconfig.txt

-rw-r--r--. 1 root root 4940 Aug 12:37 man.config

-rw-r--r--. 1 root root 2184 Aug 13:02 man.config.gz

4. Test the compressed file is wrong

[Root@localhost tmp]# Gzip-tv man.config.gz

Man.config.gz:OK

which

-T parameter check if the compressed file is wrong

The-v parameter displays more detailed information, is used in the compression process, and can display the compression ratio and so on.

[Root@localhost tmp]# gzip-v Man.config

man.config:56.4%--Replaced with man.config.gz

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

5.gzip has 9 compression levels where-9 compression is the best-1 compression speed the fastest default compression level is-6

[Root@localhost tmp]# Gzip-cv-1 man.config >>man.config1.gz

man.config:53.4%

[Root@localhost tmp]# gzip-cv-9 man.config >>man.config9.gz

man.config:56.4%

[Root@localhost tmp]# LL

Total 20

-rw-r--r--. 1 root root 2730 June 03:45 Chkconfig.txt

-rw-r--r--. 1 root root 4940 Aug 12:37 man.config

-rw-r--r--. 1 root root 2332 Aug 13:14 man.config1.gz

-rw-r--r--. 1 root root 2184 Aug 13:15 man.config9.gz

As you can see, different compression ratios do make a difference.

Let's go over Linux. Another commonly used compression command bzip2 it uses the same method as gzip, but it generates a file suffix named. bz2 we actually do it.

[Root@localhost tmp]# bzip2-zkv Man.config

Man.config:2.251:1, 3.555 Bits/byte, 55.57% saved, 4940 in, 2195 out.

[Root@localhost tmp]# LL

Total 24

-rw-r--r--. 1 root root 2730 June 03:45 Chkconfig.txt

-rw-r--r--. 1 root root 4940 Aug 12:37 man.config

-rw-r--r--. 1 root root 2332 Aug 13:14 man.config1.gz

-rw-r--r--. 1 root root 2184 Aug 13:15 man.config9.gz

-rw-r--r--. 1 root root 2195 Aug 12:37 man.config.bz2

Where you need to add-Z Parameters for compression

-K can keep source files

From the compression result, BZIP2 has a better compression effect.

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.