2018-4-17

6.1 Introduction to Compression and Packaging

6.2 gzip compression tool

6.3 bzip2 compression tool

6.4 xz compression tool






6.1 Introduction to Compression and Packaging

Linux compressed files: .zip , .gz , .bz2 , .xz , .tar.gz , .tar.bz2 , .tar.xz.

Compression can make the file smaller, which is very convenient for transmission and storage.

Although linux and windows are different, the suffix name is not so important. But in order to be easy to distinguish, it is best to set the suffix name that is easy to identify.




6.2 gzip compression tool

image.png

experiment:

Go to the /tmp/ directory, create a directory d6z, and then enter this directory.

image.png

Find one more file

image.png

image.png


Then output all these files to 1.txt

image.png

(Command meaning: all files, names, cat for each file, and append to 1.txt when finished)


image.png

You can see that the size of 1.txt is 252kb

A little small, add a few more times

image.png

image.png

There are some problems with the several appends in the middle, which may cause the decompression to be different from the original size (there are gaps)


image.png

2.9m Total lines 51543


image.png

Compress it and 1.txt is gone, it becomes 1.txt.gz and the size becomes 536k 


unzip gzip -d 

image.png

After decompression, it becomes 2M, the original is 2.9M, in fact, there are some empty spaces, which will be squeezed out.


gzip - number (1-9) to adjust the compression level. The default is level 6.

If the maximum compression is 1, the CPU consumption will be very large, and similarly 9 will be very small. Just keep the default.


There is also a gunzip that can also be decompressed

image.png

Using 9 levels of compression is similar to the original, because this is basically the compression limit. No matter how many are almost the same.


The compressed file cannot be cat, you can use file to view the information

image.png


There is also a command to view the contents of the compressed file zcat 1.txt.gz (actually decompress and then cat)


Specify a directory when compressing, and the method to prevent the file from disappearing

gzip -c 1.txt > /root/1.txt.gz

image.png

This file has not disappeared, and there is more gz under tmp


I don't want to make the decompressed files disappear when I decompress the same

image.png

image.png


gzip cannot compress directory





6.3 bzip2 compression tool

image.png

Compared with gzip compression, the more severe the compression, the more CPU resources are consumed.


Install bzip2. yum install -y bzip2

Still using 1.txt for experiments, the usage is almost the same as gzip

image.png

It is also not possible to compress directories. Almost the same as the gzip2 operation above, also with a default compression level of 9. You can also use file to view file information

There is a bzcat corresponding to zcat.





6.4 xz compression tool

image.png

The usage is almost the same as the previous two. xz 22.txt

image.png

Even smaller than bz compression, unxz is also a decompression command.

Other operations are the same as above.




Guess you like

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