Home > Operation and Maintenance > Linux Operation and Maintenance > Shell command file compression and decompression gzip, zip detailed explanation

Shell command file compression and decompression gzip, zip detailed explanation

little bottle
Release: 2019-04-29 09:32:23
forward
4572 people have browsed it

The main content of this article is about gzip and zip for file compression and decompression in shell commands. It has certain reference value. Interested friends can learn about it. I hope it will be helpful to you.

1.gzip: gzip compression tool

Function description of gzip command:

gzip command is used to compress files. gzip is a widely used compression program. After a file is compressed by it, a .gz extension will appear after its name.

The syntax format of the gzip command:

gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ... ]
gzip [-acdfhlLnNqrtvV][-S <压缩字尾字符串>][-<压缩效率>][--best/fast][文件...] 或 gzip [-acdfhlLnNqrtvV][-S <压缩字尾字符串>][-<压缩效率>][--best/fast][目录]
Copy after login

Common parameters description of the gzip command:

gzip has many parameters, as follows: Parameters and descriptions of the gzip command:

Parameter options Explanation

-a or --ascii Use ASCII text mode.

-c or --stdout or --to-stdout Output the compressed file to the standard output device without changing the original file.

-d or --decompress or ----uncompress Uncompress the compressed file.

-f or --force Forcibly compress the file. Ignores whether the file name or hard link exists and whether the file is a symbolic link.

-h or --help Online help.

-l or --list Lists information about compressed files.

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

-n or --no-name When compressing a file, the original file name and timestamp will not be saved.

-N or --name When compressing a file, save the original file name and timestamp.

-q or --quiet Does not display warning messages.

-r or --recursive Recursive processing, all files and subdirectories in the specified directory will be processed together.​

-S or ----suffix Change the compressed suffix string.

-t or --test Test whether the compressed file is correct.

-v or --verbose Display the instruction execution process.

-V or --version Display version information.​

- Compression efficiency is a value between 1 and 9. The default value is "6". The larger the value specified, the higher the compression efficiency will be.

--best The effect of this parameter is the same as specifying the "-9" parameter.​

--fast ​ The effect of this parameter is the same as specifying the "-1" parameter.

Practical operation of gzip command

Example 1: Compressed file

[root@m01 ~]#  ls  <-->显示当前目录文件
a.c b.h d.cpp
[root@m01 ~]# gzip *  <-->压缩目录下的所有文件[root@w3cschool.cc a]# 
[root@m01 ~]# ls   <-->显示当前目录文件
a.c.gz    b.h.gz    d.cpp.gz
Copy after login

Example 2: Continuing from Example 1, list detailed information

[root@m01 ~]#  gzip -dv *  <-->解压文件,并列出详细信息
a.c.gz:     0.0% -- replaced with a.c
b.h.gz:     0.0% -- replaced with b.h
d.cpp.gz:     0.0% -- replaced with d.cpp
Copy after login

Example 3: Continuing from Example 1, display compressed file information

[root@m01 ~]# gzip -l *
     compressed    uncompressed ratio uncompressed_name
         24          0  0.0% a.c
         24          0  0.0% b.h
         26          0  0.0% d.cpp
Copy after login

2. zip: Compression tool

Function description of zip command

zip command is used to compress files. zip is a widely used compression program that compresses files to produce compressed files with a .zip extension.

The syntax format of zip command

zip [-aABcdDeEfFghjklLmoqrRSTuvVwXyz!@$] [--longoption ...] [-b path] [-n suffixes] [-t date] [-tt date]
zip [-AcdDfFghjJKlLmoqrSTuvVwXyz$][-b <工作目录>][-ll][-n <字尾字符串>][-t <日期时间>][-<压缩效率>][压缩文件][文件...][-i <范本样式>][-x <范本样式>]
Copy after login

Common parameter description of zip command:

zip There are many parameters, as follows zip Command parameters and descriptions:

Parameter options Explanation

-A Adjust the executable automatic decompression file.

-b Specifies the directory where files are temporarily stored.

-c Add comments to each compressed file.

-d Delete the specified file from the compressed file.

-D Does not create a directory name in the compressed file.

-f The effect of this parameter is similar to that of specifying the "-u" parameter, but it not only updates existing files, but if some files do not originally exist in the compressed file, using this parameter will add them to the compression. in the file.

-F Try to repair damaged compressed files.

-g Compress the file and append it to the existing compressed file instead of creating a new compressed file.

-h Online help.

-i