Use of Linux gzip command

Use of Linux gzip command

1. Command Introduction

The gzip (GNU zip) command is used to compress and decompress files. It is a command often used in Linux systems to compress and decompress files. It uses the LZ77 lossless compression algorithm. The compressed files generally use the .gz suffix.

gzip can not only be used to compress large, seldom 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 file size has two obvious benefits. One is that it can reduce storage space. The other is that when transferring files over the network, it can reduce the transmission time.

2. Command format

gzip [ -acdfhlLnNrtvV19 ] [-S SUFFIX ] [ NAME... ]

3. Option Description

-a --ascii
	Use ASCII text mode. Use local conventions when converting end-of-line characters. This option is supported only on some non-Unix systems. For MSDOS, convert CR LF to LF when compressing, and convert LF to CR LF when decompressing
-c, --stdout, --to-stdout
	Output the compressed file to standard output without changing the original file -d, --decompress, --uncompress
	unzip -f, --force
	Force 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 relevant information of compressed files -L, --license
	Display copyright information and exit -n, --no-name
	When compressing files, the original file names and timestamps are not saved. When decompressing, the original file name and timestamp will not be restored even if they exist. This option is the default option when decompressing -N, --name
	When compressing, always save the original filename and timestamp; this is the default. When decompressing, the original filename and timestamp are restored if they exist. This option is useful on systems that limit file name lengths or where timestamps are lost after file transfers. -q, --quiet
	Do not display warning messages -r, --recursive
	Recursive processing, process all files and subdirectories under the specified directory together -S, --suffix=SUFFIX
	Change the suffix of the compressed and decompressed files -t, --test
	Test whether the compressed file is correct -v, --verbose
	Display the command execution process -V, --version
	Show version information and exit -#, --best, --fast
	Specifies the compression effect. The compression ratio is a value between 1 and 9. The larger the value, the higher the compression ratio and the lower the compression speed. The default value is 6. --best is equivalent to -9, --fast is equivalent to -1

4. Common Examples

(1) The original file is not compressed.

gzip /etc/passwd

The compressed /etc/passwd will become /etc/passwd.gz.

(2) Keep the original file compression.

gzip -c /etc/passwd > passwd.gz

(3) Display the instruction execution process during compression.

gzip -v /etc/passwd
/etc/passwd: 57.9% -- replaced with /etc/passwd.gz

(4) Decompress the .gz file without retaining 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 detailed content of the use of Linux gzip command. For more information about Linux gzip command, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Usage of Linux userdel command
  • Use of Linux date command
  • How to run Linux commands in the background
  • Use of Linux stat command
  • Use of Linux ls command
  • Use of Linux ln command
  • Linux cut command explained
  • Use of Linux bzip2 command

<<:  The difference between char and varchar in MYSQL

>>:  js to achieve sliding carousel effect

Recommend

Summary of important components of MySQL InnoDB

Innodb includes the following components 1. innod...

MySQL InnoDB monitoring (system layer, database layer)

MySQL InnoDB monitoring (system layer, database l...

XHTML no longer uses some obsolete elements in HTML

When we do CSS web page layout, we all know that i...

Introduction to the use of MySQL pt-slave-restart tool

Table of contents When setting up a MySQL master-...

3 common errors in reading MySQL Binlog logs

1. mysqlbinlog: [ERROR] unknown variable 'def...

Detailed explanation of the entry-level use of MySql stored procedure parameters

Use of stored procedure in parameters IN paramete...

Practice of el-cascader cascade selector in elementui

Table of contents 1. Effect 2. Main code 1. Effec...

Detailed explanation of the steps to build a Vue project with Vue-cli

First you need to install Vue-cli: npm install -g...

Pure CSS to implement iOS style open and close selection box function

1 Effect Demo address: https://www.albertyy.com/2...

Use of docker system command set

Table of contents docker system df docker system ...

Summary of the execution issues between mysql max and where

Execution problem between mysql max and where Exe...

Detailed explanation of non-parent-child component communication in Vue3

Table of contents First method App.vue Home.vue H...

Vue realizes the product magnifying glass effect

This article example shares the specific code of ...

Why is the scroll bar on the web page set on the right?

Why are the scroll bars of the browsers and word ...