Linux gzip Command
The Linux gzip command is used to compress files.
gzip is a widely used compression program that, when used on files, appends a ".gz" extension to the filename.
Syntax
gzip [-acdfhlLnNqrtvV][-S <压缩字尾字符串>][-<压缩效率>][--best/fast][文件...] or gzip [-acdfhlLnNqrtvV][-S <压缩字尾字符串>][-<压缩效率>][--best/fast][目录]
Parameters:
- -a or --ascii: Use ASCII text mode.
- -c or --stdout or --to-stdout: Output the compressed file to the standard output device without modifying the original file.
- -d or --decompress or --uncompress: Decompress the file.
- -f or --force: Compress files forcibly, ignoring 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 information about the compressed file.
- -L or --license: Display version and copyright information.
- -n or --no-name: When compressing, do not save the original file name and timestamp.
- -N or --name: When compressing, save the original file name and timestamp.
- -q or --quiet: Do not display warning messages.
- -r or --recursive: Recursively process all files and subdirectories in the specified directory.
- -S<压缩字尾字符串> or --suffix<压缩字尾字符串>: Change the compression suffix.
- -t or --test: Test if the compressed file is correct.
- -v or --verbose: Display the execution process of the command.
- -V or --version: Display version information.
- -<压缩效率>: The compression efficiency is a value between 1 and 9, with the default being "6". A larger value specifies higher compression efficiency.
- --best: This parameter has the same effect as specifying "-9".
- --fast: This parameter has the same effect as specifying "-1".
Examples
Compress files:
[[email protected] a]# ls // Display current directory files
a.c b.h d.cpp
[[email protected] a]# gzip * // Compress all files in the directory
[[email protected] a]# ls // Display current directory files
a.c.gz b.h.gz d.cpp.gz
[[email protected] a]#
Continuing from Example 1, list detailed information:
[[email protected] a]# gzip -dv * // Decompress files and list detailed information
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
[[email protected] a]#
Continuing from Example 1, display information about compressed files:
[[email protected] a]# 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