Used to compress files
gzip command is used to compress files. gzip is a widely used compression program. After a file is compressed by it, its name will have multiple ".gz" extensions after it.
gzip is a command commonly used in Linux systems to compress and decompress files. It is convenient and easy to use. Gzip can not only be used to compress large, rarely used files to save disk space, but can also be used together with the tar command to form a popular compressed file format in the Linux operating system. According to statistics, the gzip command has a compression rate of 60% to 70% for text files. Reducing the file size has two obvious benefits. One is that it can reduce storage space, and the other is that it can reduce the transmission time when transferring files over the network.
gzip(options)(parameters)
-a or --ascii: use ASCII text mode;
-d or --decompress or ----uncompress: decompress the compressed file;
-f or --force: Forcefully compress the file. Ignore whether the file name or hard link exists and whether the file is a symbolic link;
-h or --help: online help;
-l or --list: List related information of compressed files;
-L or --license: displays 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: do not display warning messages;
-r or --recursive: recursive processing, processing all files and subdirectories in the specified directory together;
-S or <compressed suffix string> or ----suffix <compressed suffix string>: change the compressed suffix string;
-t or --test: Test whether the compressed file is correct;
-v or --verbose: displays the instruction execution process;
-V or --version: display version information;
-<Compression efficiency>: 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.
-num Use the specified number num to adjust the compression speed. -1 or --fast indicates the fastest compression method (low compression ratio), -9 or --best indicates the slowest compression method (high compression ratio). The system default value is 6.
-c or --stdout or --to-stdout: Keep the original file and generate the standard output stream (used in combination with redirection).
File list: Specify the file list to be compressed.
Compress each file in the test6 directory into a .gz file
gzip*
Unzip each compressed file in the above example and list detailed information
gzip -dv *
Detailed display of information about each compressed file in Example 1 without decompression
gzip -l *
Compress a tar backup file. The extension of the compressed file is .tar.gz.
gzip -r log.tar
Recursive compressed directories
gzip -rv test6
In this way, all the files under test have become *.gz, and the directory still exists, but the files in the directory have correspondingly changed to *.gz. This is compression, which is different from packaging. Because it is operating on a directory, you need to add the -r option, so that you can also recurse on subdirectories.
Unzip directories recursively
gzip -dr test6
Keep original files and redirect compression/decompression streams to new files
gzip -c aa > aa.gz
gzip -dc bb.gz > bb