Linux commands: Gzip/gunzip command-compression and decompression

Source: Internet
Author: User

Gzip/gunzip command

Function description

Compress files (gzip) or unzip (gunzip), compressed file presets with the extension ". Gz", Gunzip is the hard link of gzip, decompression can be achieved by gzip-d command . Use the following:

gzip [option] compress (unzip) the document name

Common parameters

Options Description
-D Decompression of compressed Files (equivalent to the decompression function of Gunzip)
-C Standard output of the result output (equivalent to preserving the source file)
-R Recursive compression of all files in the specified directory and sub-directories
-T Check for compressed file integrity
-V For each compressed and uncompressed document, the corresponding file name and compression ratio are displayed
-L Displays compressed information for compressed files, showing fields as compressed document size, uncompressed document size, compression ratio, and uncompressed document names
-num Configures the compression ratio with the specified number num, "1" or "-fast" for the minimum compression ratio, "9" or "-best" for the maximum compression ratio, the system default compression ratio is 6

Example

Unzip demo

[Email protected] app]# cp/var/log/messages./ #复制message到当前目录

[Email protected] app]# ll-h #查看message的大小是12K

Total dosage 2.4M

-rw-r--r--. 1 root root 1.2M October 12:09 glances-1.7.1.tar.gz

-RW-------. 1 root root 12K November 14:08 messages

-rw-r--r--. 1 root root 1.2M October 15:27 nginx-1.2.9.zip

[Email protected] app]# gzip messages #压缩message

[Email protected] app]# ll-h #压缩后的message大小是1.2K

Total dosage 2.4M

-rw-r--r--. 1 root root 1.2M October 12:09 glances-1.7.1.tar.gz

-RW-------. 1 root root 1.2K November 14:08 messages.gz

-rw-r--r--. 1 root root 1.2M October 15:27 nginx-1.2.9.zip

[Email protected] app]# gzip-d messages.gz #解压后的message还原

[Email protected] app]# ll-h

Total dosage 2.4M

-rw-r--r--. 1 root root 1.2M October 12:09 glances-1.7.1.tar.gz

-RW-------. 1 root root 12K November 14:08 messages

-rw-r--r--. 1 root root 1.2M October 15:27 nginx-1.2.9.zip

Description

you can see from the above operation that the message file is compressed from the original 12K to 1.2K, the effect is obvious. The gzip command execution deletes the source files, whether compressed or uncompressed.

Use the-c parameter to preserve the source file

[Email protected] app]#gzip-c messages > messages.gz #使用-C parameter Compression   

[Email protected] app]# ll-h #源文件还在

Total dosage 2.4M

-rw-r--r--. 1 root root 1.2M October 12:09 glances-1.7.1.tar.gz

-RW-------. 1 root root 12K November 14:08 messages

-rw-r--r--. 1 root root 1.2K November 14:36 messages.gz

-rw-r--r--. 1 root root 1.2M October 15:27 nginx-1.2.9.zip

[[email protected] app]# gzip-9-C messages > messages2.gz #使用-9 minimum compression ratio, is the smallest

use Zcat to find out what 's on your file

[Email protected] app]# zcat messages.gz | less

Nov 04:01:01 C7 systemd:created Slice user-0.slice.

Nov 04:01:01 C7 systemd:starting Session 94 of user root.

Nov 04:01:01 C7 systemd:started Session 94 of user root.

Nov 05:01:01 C7 systemd:created Slice user-0.slice.

...... Slightly


Learn from:

Karst "Progressive Linux"

Marco Linux

This article is from the "Zhao Dongwei blog" blog, make sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1875410

Linux commands: Gzip/gunzip command-compression and decompression

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.