Linux Study Notes - Compression and Decompression Commands

1.11. Compression and decompression commands

 

Compression format:

.gz common in Linux

.rar Windows common

.zip Linux, Windows can support, no need to install additional software.

1.11.1.gzip

Compressed file

Only files can be compressed, not directories.

Compress and decompress without preserving original files.

 

[root@localhost cn]# ls

china.log

[root@localhost cn]# gzip china.log

[root@localhost cn]# ls

china.log.gz

 

After compression, the original file no longer exists.

 

Unzip: gzip -d 

After decompression, the compressed package no longer exists

[root@localhost cn]# gzip -d china.log.gz

[root@localhost cn]# ls

china.log

 

cannot compress directory

[root@localhost cn]# mkdir gd

[root@localhost cn]# ls

china.log  gd

[root@localhost cn]# gzip gd

gzip: gd is a directory -- ignored

[root@localhost cn]#

 

 

1.11.2.gunzip

Unzip, similar to the gzip -d command

 

[root@localhost cn]# ls

china.log.gz  gd

[root@localhost cn]# gunzip china.log.gz

[root@localhost cn]# ls

china.log  gd

[root@localhost cn]#

 

1.11.3.tar

Package directory, compressed format: .tar.gz

 

1. You can keep the original file

2, can compress the directory

 

-c pack

-v show details

-f specifies the filename

-z when packing, also compress

 

After packaging, use gzip compression

[root@localhost cn]# tar -cvf gd.tar gd

gd/

[root@localhost cn]# ls

china.log gd  gd.tar

 [root@localhost cn]# gzip gd.tar

[root@localhost cn]# ls

china.log  gd  gd.tar.gz

[root@localhost cn]#

 

Compress directly when packing

 

[root@localhost cn]# tar -zcvf gd2.tar.gz gd

gd/

[root@localhost cn]# ls

china.log gd  gd2.tar.gz   gd.tar.gz

[root@localhost cn]#

 

 

unzip

-x unpack

-v show details

-f specifies the decompression file name

-z decompress

 

[root@localhost cn]# tar -zxvf gd2.tar.gz

gd/

[root@localhost cn]# ls

china.log  gd   gd2.tar.gz gd.tar.gz

[root@localhost cn]#

 

 

1.11.4.zip

Compressed file or directory

zip [-r] [ compressed filename ] [ file or directory ]

 

-r zip directory

 

Linux compression formats, Windows compressed files are almost supported.

Windows compression, Linux does not necessarily support, except for zip format.

 

original file can be kept

directory can be compressed

 

 

zip install

-bash: zip: command not found

It is because the zip command is not installed on the liunx server , you need to install it

linux install zip command:

yum install zip

 

Compressed files, the compression ratio is not impressive

[root@localhost cn]# ls

china.log  gd

[root@localhost cn]# zip china.zip china.log

  adding: china.log (stored 0%)

[root@localhost cn]# ls

china.log  china.zip  gd

 

[root@localhost cn]#

 

1.11.5.unzip

linux install unzip command:

yum install unzip

                           

Unzip the compressed package in zip format.

 

[root@localhost cn]# unzip china.zip

Archive:  china.zip

replace china.log? [y]es, [n]o, [A]ll, [N]one, [r]ename: y

 extracting: china.log

[root@localhost cn]# ls

china.log  china.zip  gd

[root@localhost cn]#

 

 

1.11.6.bzip2

Upgraded version of gzip

 

Compression format: .bz2

 

-k means to keep the original file after generating the compressed file.

 

This format has a better compression ratio.

 

bzip2 install

yum install bzip2

 

Compress the file, keep the original file

[root@localhost cn]# bzip2 -k china.log

[root@localhost cn]# ls

china.log  china.log.bz2  china.zip  gd

[root@localhost cn]#

 

 

use with tar

The -j option in the tar command means to use bzip2

       -j, --bzip2

              filter the archive through bzip2

 

[root@localhost cn]# tar -cjf gd.tar.bz2 gd

[root@localhost cn]# ls

china.log  china.log.bz2  china.zip  gd  gd.tar.bz2

 

[root@localhost cn]#

 

1.11.7.bunzip2

Unzip the bz2 archive

 

When decompressing, keep the original file –k means keep the original file

[root@localhost cn]# bunzip2 -k china.log.bz2

bunzip2: Output file china.log already exists.

 

Use tar to decompress the bz2 archive – x means decompress

 

[root@localhost cn]# tar -xjf gd.tar.bz2

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325960037&siteId=291194637