The gzip commands for Linux commands to understand and use instances

Source: Internet
Author: User
Tags gz file

Gzip can be used not only to compress large, less-used files to conserve disk space, but also to form the more popular compressed file format in Linux operating systems, along with the tar command. 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, the file after it compressed, after its name will be more than ". gz" extension.

  3. Command parameters:

-A or--ASCII uses ASCII text mode.

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

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

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

-H or--help online Help.

-L or--list lists information about compressed files.

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

-N or--no-name compressed files, the original file name and time stamp are not saved.

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

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

-R or--recursive recursively, all files and subdirectories under the specified directory are processed together.

-s< compressed Word tail string > or----suffix< compressed word tail string > Change compressed Word tail string.

-T or--test test that the compressed file is correct.

The-V or--verbose displays the instruction execution process.

-V or--version display version information.

-num adjusts the speed of the 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 default value for the system is 6.

  4. Use instance:

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

Command:

The code is as follows:

Gzip *

Output:

The code is as follows:

[Root@localhost 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

[Root@localhost test6]# gzip *

[Root@localhost 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

[Root@localhost test6]#

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

Command:

The code is as follows:

GZIP-DV *

Output:

The code is as follows:

[Root@localhost 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

[Root@localhost 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

[Root@localhost 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

[Root@localhost test6]#

Example 3: Detailed display of information for each compressed file in Example 1, and no pressure

Command:

The code is as follows:

Gzip-l *

Output:

The code is as follows:

[Root@localhost 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)

Example 4: Compresses a tar backup file, at which point the file name extension is. tar.gz

Command:

The code is as follows:

Gzip-r Log.tar

Output:

The code is as follows:

[Root@localhost test]# Ls-al Log.tar

-rw-r--r--1 root root 307200 11-29 17:54 Log.tar

[Root@localhost test]# gzip-r Log.tar

[Root@localhost test]# Ls-al log.tar.gz

-rw-r--r--1 root root 1421 11-29 17:54 log.tar.gz

Instance 5: Recursive compressed directory

Command:

The code is as follows:

GZIP-RV Test6

Output:

The code is as follows:

[Root@localhost 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

[Root@localhost test6]# CD ...

[Root@localhost 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

[Root@localhost test]# CD Test6

[Root@localhost 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 are *.gz, the directory is still there, but the files in the directory are *.gz. This is compression, and packaging is different. Because it is a directory operation, you need to add the-r option, which can also be recursive for subdirectories.

Example 6: Recursively extract the Directory

Command:

The code is as follows:

GZIP-DR Test6

Output:

The code is as follows:

[Root@localhost 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

[Root@localhost test6]# CD ...

[Root@localhost test]# gzip-dr Test6

[Root@localhost test]# CD Test6

[Root@localhost 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

[Root@localhost test6]#

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.