Learn a Linux command every day (40): gzip

Time:2021-10-17

Learn a Linux command every day (40): gzip

Yesterday’s recommendation:Learn a Linux command every day (39): Tar

Command introduction

The gzip command is used to compress files, and the gzip and gunzip commands are used to compress or expand files in GNU gzip format.

If the compressed file name is too long for its file system, gzip truncates it. By default, gzip keeps the original file name, timestamp and other information in the newly generated compressed file.

Syntax format

gzip [ OPTIONS ]  [ name ]
gunzip [ OPTIONS ] [ name ]

Option description

-a   # Use ASCII text mode
-c   # Writes the output to standard output, leaving the original file unchanged.
-d   # Unzip file
-f   # Force compressed file
-h   # Display online help information
-l   # Lists information about compressed files
-L   # Display version and copyright information
-n   # When compressing a file, the original file name, timestamp and other attribute information are not retained
-N   # When compressing a file, keep the original file name and timestamp attribute information
-q   # Do not display warning messages
-r   # Recursive processing, processing all files and subdirectories in the specified directory together
-t   # Test whether the compressed file is correct
-v   # Display command execution process information
-V   # display version information
-< compression efficiency >   # Compression efficiency is a value between 1 and 9. The default value is "6". The higher the specified value, the higher the compression rate

Application examples

Compress all files in the current directory into a. GZ package

[[email protected] testdir]# gzip *
[[email protected] testdir]# ll
total 24
-rw-r--r-- 1 root root 59 Jan 16 12:15 cest.txt.gz
-rw-r--r-- 1 root root 57 Jan 16 12:12 cuttest.txt.gz
-rw-r--r-- 1 root root 81 Jan 16 09:55 mingongge1.txt.gz
-rw-r--r-- 1 root root 51 Jan 16 03:36 mingongge2.txt.gz
-rw-r--r-- 1 root root 87 Jan 16 09:59 mingongge.txt.md5.gz
-rw-r--r-- 1 root root 65 Jan 16 10:19 sort.cut.txt.gz

Unzip each compressed file in the current directory and list the detailed information

[[email protected] testdir]# gzip -dv *
cest.txt.gz:  77.8% -- replaced with cest.txt
cuttest.txt.gz:  73.5% -- replaced with cuttest.txt
mingongge1.txt.gz:  61.3% -- replaced with mingongge1.txt
mingongge2.txt.gz:  25.0% -- replaced with mingongge2.txt
mingongge.txt.md5.gz:  -4.1% -- replaced with mingongge.txt.md5
sort.cut.txt.gz:  19.0% -- replaced with sort.cut.txt
[[email protected] testdir]# ll
total 24
-rw-r--r-- 1 root root 144 Jan 16 12:15 cest.txt
-rw-r--r-- 1 root root 102 Jan 16 12:12 cuttest.txt
-rw-r--r-- 1 root root 124 Jan 16 09:55 mingongge1.txt
-rw-r--r-- 1 root root  24 Jan 16 03:36 mingongge2.txt
-rw-r--r-- 1 root root  49 Jan 16 09:59 mingongge.txt.md5
-rw-r--r-- 1 root root  42 Jan 16 10:19 sort.cut.txt

The information of each compressed file in the current directory is displayed in detail, but the file is not extracted

[[email protected] testdir]# gzip -l *
         compressed        uncompressed  ratio uncompressed_name
                 59                 144  77.8% cest.txt
                 57                 102  73.5% cuttest.txt
                 81                 124  61.3% mingongge1.txt
                 51                  24  25.0% mingongge2.txt
                 87                  49  -4.1% mingongge.txt.md5
                 65                  42  19.0% sort.cut.txt
                400                 485  23.9% (totals)

The common usage of the tar command is basically the same as that of the attribute file compression and decompression command.

Learn a Linux command every day (40): gzip

Recommended Today

SQL exercise 20 – Modeling & Reporting

This blog is used to review and sort out the common topic modeling architecture, analysis oriented architecture and integration topic reports in data warehouse. I have uploaded these reports to GitHub. If you are interested, you can have a lookAddress:https://github.com/nino-laiqiu/TiTanI recorded a relatively complete development process in my hexo blog deployed on GitHub. You can […]