Use of Linux gzip Command
- 2021-08-28 21:42:44
- OfStack
1. Brief introduction to commands
gzip (GNU zip) command is used to compress and decompress files. It is a command that is often used in Linux system to compress and decompress files. LZ77 lossless compression algorithm is adopted, and the compressed files generally use. gz suffix.
gzip can not only be used to compress large and less used files to save disk space, but also form a popular compressed file format in Linux operating system together with tar command 1. According to statistics, gzip command has a compression ratio of 60% ~ 70% for text files. Reducing file size has two obvious benefits: 1. It can reduce storage space, and 2. It can reduce the transfer time when transferring files over the network.
2. Command format
gzip [ -acdfhlLnNrtvV19 ] [-S SUFFIX] [ NAME... ]
3. Description of options
-a --ascii
Use ASCII Text mode. Use local conventions when converting end-of-line characters. This option is only available for certain non- Unix Support on the system. For MSDOS When compressed, the CR LF Convert to LF When unzipped, the LF Convert to CR LF
-c, --stdout, --to-stdout
Output the compressed file to standard output without changing the original file
-d, --decompress, --uncompress
Decompression
-f, --force
Forced compression or decompression, even if the file has multiple links or the corresponding file already exists, or the compressed data is read from or written to the terminal
-h, --help
Display help information and exit
-l, --list
List information about compressed files
-L, --license
Display copyright information and exit
-n, --no-name
When compressing a file, the original file name and timestamp are not saved. When decompressed, the original file name and timestamp are not restored even if they exist. This option is the default option when extracting
-N, --name
When compressing, always save the original file name and timestamp; This is the default. When decompressing, if it exists, the original file name and timestamp are restored. This option is useful for systems that limit the length of a file name or for systems that lose a timestamp after a file transfer
-q, --quiet
Do not display warning messages
-r, --recursive
Recursive processing, all files and subdirectories in the specified directory 1 And process
-S, --suffix=SUFFIX
Change the suffix name of the compressed and decompressed file
-t, --test
Test whether the compressed file is correct
-v, --verbose
Display instruction execution process
-V, --version
Display version information and exit
-#, --best, --fast
Specifies the compression effect. Compression ratio is 1 A between 1~9 The larger the value, the higher the compression ratio and the lower the compression speed, and the default is 6 . --best Equivalent to -9 , --fast Equivalent to -1
4. Common examples
(1) Do not keep the original file compressed.
gzip /etc/passwd
The compressed the/etc/passwd becomes the/etc/passwd. gz.
(2) Keep the original file compressed.
gzip -c /etc/passwd > passwd.gz
(3) Display the instruction execution process when compressing.
gzip -v /etc/passwd
/etc/passwd: 57.9% -- replaced with /etc/passwd.gz
(4) Extract the. gz file without keeping the original file.
gzip -dv /etc/passwd.gz
/etc/passwd.gz: 57.9% -- replaced with /etc/passwd
(5) Recursively compress all files in the specified directory.
ls dir
file1 file2 file3
gzip -rv dir
dir/file3: -10.0% -- replaced with dir/file3.gz
dir/file2: -25.0% -- replaced with dir/file2.gz
dir/file1: -16.7% -- replaced with dir/file1.gz
The above is the use of Linux gzip command details, more information about Linux gzip command please pay attention to other related articles on this site!