Day18--linux gzip, bzip2, XZ three compression tools introduction

Source: Internet
Author: User
Tags bz2

6.1: Compression Packaging Introduction:

Compression: Saves space, facilitates transport, and consumes less bandwidth resources:

Common types of compressed files:

Windows: . rar. zip. 7z

Linux: . zip. gz. bz2. xz. tar.gz. tar.bz2. Tar.xz


1. Compression tool gzip: (Cannot compress directory, and delete source files after compression)

Syntax: gzip [-d1-9] File

-D: Use when compressing source files (in conjunction with gzip) "=======>gunzip (same effect)

1-9: Refers to the compression level, 1 is the worst ( maximum ), 9 is the best ( minimum ), the default is 6.

1.1: First I prepare a large content file, the effect is more obvious

[[email protected] ~]# du -sh 11.txt              #查看此文件大小的内容为2M. 2.0m    11.txt[[email protected] ~]#  gzip 11.txt              # gzip to compress it:[[email protected] ~]# du -sh 11.txt.gz           #压缩后大小为24K, obvious effect: 24k     11.txt.gz[[email protected]  ~]# gzip -d 11.txt.gz         #使用gzip对其加压缩: [[email  protected] ~]# gzip -1 11.txt             #使用压缩级别1 (worst) to compress text:[[email protected] ~]# du -sh 11.txt.gz           #压缩后大小变为240K:240k    11.txt.gz[[email  Protected] ~]# gunzip 11.txt.gz          #使用gunzip进行解压缩: 

As we know, there are two types of text compression commands:

Gzip- D file (-D must be added)

Gunzip file (no parameters required)

1.2:gzip also supports viewing of compressed file content :

Syntax: zcat filename

[Email protected] ~]# zcat 1.txt.gz #使用zcat进行查看root: X:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaem On:x:2:2:daemon:/sbin:/sbin/nologin

1.3:gzip also supports preserving source files when compressing : (-C)

Syntax: Gzip-c source file after compressed file name (both names cannot be the same)

[Email protected] ~]# gzip-c 1.txt > 2.txt.gz

[Email protected] ~]# gzip-dc 1.txt.gz > 5.txt #将文件解压后到5. txt file:

Note: Sometimes after you keep the source file, and then unzip the file will be prompted to exist, you cannot extract:

[Email protected] ~]# bzip2-d 1.txt.bz2

Bzip2:output file 1.txt already exists.

You can use the -df option to force overrides:

[Email protected] ~]# bzip2-df 1.txt.bz2

2, compression tool bzip2 (compression directory is not supported, the source file is not preserved after compression)

Compression level: 1-9: Default is 9

2.1: Syntax: bzip [-DZ] filename

The options are as follows:

- Z: Use when compressing files (no-Z option is also possible)

- D: Use when extracting files:

is also to prepare a relatively large content of the file:

[[email protected] ~]# du -sh 11.txt            #查看文件大小为2M: 2.0m    11.txt[[email  protected] ~]# bzip2 11.txt             #使用bzip2进行压缩, the default level is 9:[[email protected] ~]# du -sh 11.txt.bz2        #压缩后28K, the effect is more obvious: 28k     11.txt.bz2[[email protected] ~]#  bzip2 -d 11.txt.bz2     #使用bzip2  -d  uncompressed: [[email protected]  ~]# bzip2 -z1 11.txt        #使用1级别进行压缩: File 144k:[[email  protected] ~]# du -sh 11.txt.bz2       #再次查看文件大小: 144K     11.TXT.BZ2 

This results in: bzip Nine compression levels: 1 levels of compression after the largest content,9 compression after the least content.

2.2:GZIP2 also supports viewing of compressed file content :

Syntax: bzcat filename

[Email protected] ~]# bzcat 1.txt.bz2 #bzcat查看文件内容root: X:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologin

1.3:gzip also supports preserving source files when compressing : (- k )

Syntax: bzip2-k file name after compressing source files (the names of the two cannot be the same)

[Email protected] ~]# bzip2-k 1.txt > 2.txt.bz2 #保留源文件:

[Email protected] ~]# bzip2-dc 1.txt.bz2 > 5.txt #将文件解压后到5. txt file:

3, compression tool Zip: (You can also compress files and directories)--compression will retain the source files:

You can use Yum install-y zip to install

Compressed files under Windows and Linux can be common:

The syntax is as follows

compressed Files : Zip compressed file name to be compressed

Unzip file : Unzip Zip package name

3.1: Unzip the file:

[[email protected] ~]# zip 1.txt.zip 1.txt # compress the file with Zip:

Adding:1.txt (deflated 59%)

[Email protected] ~]# ls-l 1.txt 1.txt.zip

-rw-r--r--1 root root 964 November 9 21:16 1.txt

-rw-r--r--1 root root 555 November 9 22:42 1.txt.zip

3.2: Unzip directory:zip-r directory name to be compressed after compression directory

[Email protected] ~]# zip-r yuanhh.zip yuanhh

adding:yuanhh/(stored 0)

adding:yuanhh/2/(stored 0%)

adding:yuanhh/4/(stored 0%)

ADDING:YUANHH/3 (stored 0%)

Adding:yuanhh/1.bak (stored 0%)

adding:yuanhh/1.txt.bz2 (stored 0%)

[Email protected] ~]# ls-ld yuan* #源文件来存在

Drwxr-sr-x 4 Root YUANHH 63 November 9 19:24 YUANHH

-rw-r--r--1 root root 1360 November 9 23:02 Yuanhh.zip

3.2: So when extracting the file, will be prompted to overwrite it: will prompt whether to overwrite:

[Email protected] ~]# unzip Yuanhh.zip

Archive:yuanhh.zip

Replace YUANHH/3? [Y]es, [N]o, [A]ll, [N]one, [r]ename:y

Extracting:yuanhh/3

Replace Yuanhh/1.bak? [Y]es, [N]o, [A]ll, [N]one, [r]ename: y

Extracting:yuanhh/1.bak

Replace yuanhh/1.txt.bz2? [Y]es, [N]o, [A]ll, [N]one, [r]ename: y

extracting:yuanhh/1.txt.bz2

If you don't want to prompt: You can use unzip-o to compress file names

[[email protected] ~]# unzip-o yuanhh.zip #-o is automatically overwritten without prompting:

Archive:yuanhh.zip

Extracting:yuanhh/3

Extracting:yuanhh/1.bak

extracting:yuanhh/1.txt.bz2

4, Compression tool XZ: ( cannot compress the directory, and delete the source files after compression )

Syntax: XZ [-zd] File name

[[email protected] ~]# xz 1.txt # zip file

[[email protected] ~]# xz-d 1.txt.xz # unzip the file

4.1:XZ compressed; You can also keep the source file: with-C:

[Email protected] ~]# xz-c 1.txt > 1.txt.xz #压缩后保留源文件:

[Email protected] ~]# xz-dc 1.txt.xz > 5.txt #将文件解压后到5. txt file:








This article is from the "_de blog" blog, be sure to keep this source http://yuanhaohao.blog.51cto.com/7714752/1980466

Day18--linux gzip, bzip2, XZ three compression tools introduction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.