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
experiment:
Go to the /tmp/ directory, create a directory d6z, and then enter this directory.
Find one more file
Then output all these files to 1.txt
(Command meaning: all files, names, cat for each file, and append to 1.txt when finished)
You can see that the size of 1.txt is 252kb
A little small, add a few more times
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)
2.9m Total lines 51543
Compress it and 1.txt is gone, it becomes 1.txt.gz and the size becomes 536k
unzip gzip -d
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
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
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
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
gzip cannot compress directory
6.3 bzip2 compression tool
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
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
The usage is almost the same as the previous two. xz 22.txt
Even smaller than bz compression, unxz is also a decompression command.
Other operations are the same as above.