"Go" one Linux command per day: gzip command

Source: Internet
Author: User
Tags gz file

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

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 represents the fastest compression method (low compression ratio), 9 or--best represents the slowest compression method (high compression ratio). The system default value is 6.

4. Usage examples:

Example 1: Compress each file in the Test6 directory into a. gz file

Command:

Gzip *

Output:

[email protected] test6]# LL

Total 604

---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

-rw-r--r--1 root mail 0 11-30 08:39 log2014.log

-rw-r--r--1 root mail 0 11-30 08:39 log2015.log

-rw-r--r--1 root mail 0 11-30 08:39 log2016.log

-rw-r--r--1 root mail 0 11-30 08:39 log2017.log

[[Email protected] test6]# gzip *

[email protected] test6]# LL

Total 28

---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

-rw-r--r--1 root mail 11-30 08:39 log2014.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2015.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2016.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2017.log.gz

[Email protected] test6]#

Description

Example 2: Unzip each compressed file in Example 1 and list detailed information

Command:

GZIP-DV *

Output:

[email protected] test6]# LL

Total 28

---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

-rw-r--r--1 root mail 11-30 08:39 log2014.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2015.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2016.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2017.log.gz

[Email protected] test6]# GZIP-DV *

linklog.log.gz:99.6%--Replaced with Linklog.log

log2012.log.gz:99.6%--Replaced with Log2012.log

log2013.log.gz:47.5%--Replaced with Log2013.log

log2014.log.gz:0.0%--Replaced with Log2014.log

log2015.log.gz:0.0%--Replaced with Log2015.log

log2016.log.gz:0.0%--Replaced with Log2016.log

log2017.log.gz:0.0%--Replaced with Log2017.log

[email protected] test6]# LL

Total 604

---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

-rw-r--r--1 root mail 0 11-30 08:39 log2014.log

-rw-r--r--1 root mail 0 11-30 08:39 log2015.log

-rw-r--r--1 root mail 0 11-30 08:39 log2016.log

-rw-r--r--1 root mail 0 11-30 08:39 log2017.log

[Email protected] test6]#

Description

Example 3: Show details of each compressed file in Example 1, and do 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

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)

Description

Example 4: Compress a tar backup file, at which time the zip file has the extension. tar.gz

Command:

Gzip-r Log.tar

Output:

[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

Description

Example 5: Recursive compression directory

Command:

GZIP-RV Test6

Output:

[email protected] test6]# LL

Total 604

---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

-rw-r--r--1 root mail 0 11-30 08:39 log2014.log

-rw-r--r--1 root mail 0 11-30 08:39 log2015.log

-rw-r--r--1 root mail 0 11-30 08:39 log2016.log

-rw-r--r--1 root mail 0 11-30 08:39 log2017.log

[Email protected] test6]# CD.

[Email protected] test]# GZIP-RV TEST6

test6/log2014.log:0.0%--Replaced with test6/log2014.log.gz

test6/linklog.log:99.6%--Replaced with test6/linklog.log.gz

test6/log2015.log:0.0%--Replaced with test6/log2015.log.gz

test6/log2013.log:47.5%--Replaced with test6/log2013.log.gz

test6/log2012.log:99.6%--Replaced with test6/log2012.log.gz

test6/log2017.log:0.0%--Replaced with test6/log2017.log.gz

test6/log2016.log:0.0%--Replaced with test6/log2016.log.gz

[Email protected] test]# CD TEST6

[email protected] test6]# LL

Total 28

---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

-rw-r--r--1 root mail 11-30 08:39 log2014.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2015.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2016.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2017.log.gz

Description

In this way, all the files below the test become *.gz, and the directory still exists just as the files in 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.

Example 6: Extracting a directory recursively

Command:

GZIP-DR Test6

Output:

[email protected] test6]# LL

Total 28

---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

-rw-r--r--1 root mail 11-30 08:39 log2014.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2015.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2016.log.gz

-rw-r--r--1 root mail 11-30 08:39 log2017.log.gz

[Email protected] test6]# CD.

[Email protected] test]# GZIP-DR TEST6

[Email protected] test]# CD TEST6

[email protected] test6]# LL

Total 604

---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

-rw-r--r--1 root mail 0 11-30 08:39 log2014.log

-rw-r--r--1 root mail 0 11-30 08:39 log2015.log

-rw-r--r--1 root mail 0 11-30 08:39 log2016.log

-rw-r--r--1 root mail 0 11-30 08:39 log2017.log

[Email protected] test6]#

Description

"Go" one Linux command per day: gzip command

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.