Linux common Commands (26)-gzip

Source: Internet
Author: User
Tags gz file unpack

There are two obvious benefits of reducing file size, one is to reduce storage space, and the other is to reduce transmission time when transferring files over the network. Gzip is a frequently used Linux system command to compress and decompress files, which is both convenient and useful. Gzip not only compresses large, less-used files to conserve disk space, but also, together with the TAR commands, forms the most popular compressed file format in the Linux operating system. According to statistics, the gzip command has a 60%~70% compression rate for text files.

1. command format:

gzip [parameters] [file or directory]

2. command function:

Gzip is a widely used compression program, after which the file is compressed, and its name is followed by a ". gz" extension.


3. Command parameters:

-A or--ASCII use ASCII text mode.

-C or--stdout or--to-stdout the compressed file output to the standard output device, not to change the original file.

-D or--decompress or----uncompress unpack the compressed file.

-F or--force forcibly compress the file. Ignores the existence of a file name or a hard connection and whether the file is a symbolic connection.

-H or--help online Help.

-L or--list lists information about the compressed file.

-L or--license display version and copyright information.

The original file name and time stamp are not saved when the file is compressed by-N or--no-name.

-N or--name compress the file, save the original file name and time stamp.

-Q or--quiet does not display a warning message.

-R or--recursive recursively handles all files and subdirectories under the specified directory.

-s< compress the tail string > or----suffix< compress the tail string > change the compressed Word tail string.

-T or--test tests whether the compressed file is correct.

-V or--verbose shows the instruction execution process.

-V or--version displays version information.

- num Adjusts the speed of compression with the specified number num,-1 or--fast for the fastest compression method (low compression ratio), 9 or--best for the slowest compression method (high compression ratio). The system default value is 6.


4. Command instance:

Example One. compress each file in the Test6 directory into a. gz file

Command: gzip *

[[email protected] test6]# ll---xr--r--1 root mail  302108 11-30 08:39 linklog.log---xr--r--1 mail users 302108 11-30 08:39 log2012.log-rw-r--r--1 Mail users     11-30 08:39 log2013.log[[email protected] test6]# gzip *[[email protected ] test6]# ll---xr--r--1 root mail  1341 11-30 08:39 linklog.log.gz---xr--r--1 mail users 1341 11-30 08:39 Log2012.log . gz-rw-r--r--1 Mail users   11-30 08:39 log2013.log.gz[[email protected] test6]#


example Two. unzip each compressed file in Example 1 and list detailed information

Command:GZIP-DV *

[email protected] test6]# LL Total---xr--r--1 root mail  1341 11-30 08:39 linklog.log.gz---xr--r--1 mail users 1341 1 1-30 08:39 log2012.log.gz-rw-r--r--1 mail users   11-30 08:39 log2013.log.gz[[email protected] test6]# GZIP-DV *lin Klog.log.gz:  99.6%--Replaced with linklog.loglog2012.log.gz:  99.6%--Replaced with Log2012.loglog2013.log.gz:  47.5%--replaced with Log2013.log[[email protected] test6]# LL Total 604---xr--r--1 root mai L  302108 11-30 08:39 linklog.log---xr--r--1 mail users 302108 11-30 08:39 log2012.log-rw-r--r--1 Mail users     61 1 1-30 08:39 Log2013.log[[email protected] test6]#

Example Three.Detailed Example 1 shows the information of each compressed file, but does not understand the pressure

Command: Gzip-l *

Output: [[email protected] test6]# gzip-l *         compressed        uncompressed  ratio uncompressed_name               1341              302108  99.6% linklog.log               1341              302108  99.6% log2012.log                 all  47.5% Log2013.log                   0   0.0% log2014.log                   0   0.0% log2015.log                   0   0.0% Log2016.log                   0   0.0% log2017.log               2880              604277  99.5% (totals)

example Four. compresses a tar backup file, at which time the compressed file has the extension. tar.gz

command: gzip-r Log.tar

[[email protected] test]# Ls-al log.tar-rw-r--r--1 root root 307200 11-29 17:54 log.tar[[email protected] test]# gzip-r Log.tar[[email protected] test]# ls-al log.tar.gz-rw-r--r--1 root root 1421 11-29 17:54 log.tar.gz


Example Five. To compress a directory recursively

Command: GZIP-RV test6
Note: All the files under test become *.gz, and the directory remains only the files within the directory become *.gz. This is compression, and packaging is different. Because it is a directory operation, you need to add the-r option so that you can recursively return subdirectories.

[[email protected] test6]# ll---xr--r--1 root mail  302108 11-30 08:39 linklog.log---xr--r--1 mail users 302108 11-30 08:39 log2012.log-rw-r--r--1 Mail users     11-30 08:39 log2013.log[[email protected] test6]# CD. [Email protected] test]# gzip-rv test6test6/linklog.log:       99.6%--Replaced with test6/linklog.log.gztest6/ Log2013.log:       47.5%--Replaced with Test6/log2013.log.gztest6/log2012.log:       99.6%--Replaced with test6/ Log2012.log.gz[[email protected] test]# CD Test6[[email protected] test6]# ll---xr--r--1 root mail  1341 11-30 08:39 L inklog.log.gz---xr--r--1 mail users 1341 11-30 08:39 log2012.log.gz-rw-r--r--1 mail users 11-30 08:39 log2013.log   . gz


Example Six.recursively unpack a directory
Command:gzip-dr Test6

< Span style= "font-family:comic Sans MS" >

[[email protected] test6]# ll---xr--r--1 root mail  1341 11-30 08:39 linklog.log.gz---xr--r--1 mail users 1341 11-30 08:39 log2012.log.gz-rw-r--r--1 Mail users   11-30 08:39 log2013.log.gz[[email protected] test6]# CD. [[email protected] test]# gzip-dr test6[[email protected] test]# CD Test6[[email protected] test6]# ll---xr--r--1 root m  Ail  302108 11-30 08:39 linklog.log---xr--r--1 mail users 302108 11-30 08:39 log2012.log-rw-r--r--1 Mail users     61 11-30 08:39 log2013.log[[email protected]ost test6]#

Original address: http://www.cnblogs.com/peida/archive/2012/12/06/2804323.html



Linux common Commands (26)-gzip

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.