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

Vue simple implementation of turntable lottery

This article shares the specific code of Vue to s...

Learn about CSS label display mode in one article

Tag type (display mode) HTML tags are generally d...

A brief discussion on CSS3 animation jamming solutions

Why is it stuck? There is a premise that must be ...

A brief discussion on the problem of forgotten mysql password and login error

If you forget your MySQL login password, the solu...

Solution to CSS anchor positioning being blocked by the top fixed navigation bar

Many websites have a navigation bar fixed at the ...

JavaScript to achieve the effect of tab bar switching

Tab bar: Click different tabs to display differen...

React+Amap obtains latitude and longitude in real time and locates the address

Table of contents 1. Initialize the map 2. Map Po...

Example of implementing load balancing with Nginx+SpringBoot

Introduction to Load Balancing Before introducing...

Use ab tool to perform API stress test on the server

Table of contents 1 A brief introduction to syste...

vue-cli4.5.x quickly builds a project

1. Install vue-cli npm i @vue/cli -g 2. Create a ...

Vue3 AST parser-source code analysis

Table of contents 1. Generate AST abstract syntax...

Native JS to implement sharing sidebar

This article shares a sharing sidebar implemented...

How to use TypeScript in Vue

introduction In recent years, the call for TypeSc...