Compression Packaging Introduction:
Commonly used compressed file types:
1, windows:.rar/.zip/.7z
2, Linux:.zip/.gz/.bz2/.xz/.tar/.gz/.tar/.bz2/.tar/.xz
Gzip Compression Tool:
1, experiment, CD to/tmp directory, use MKDI to create a directory d6z, in the CD to d6z directory to create a text 1.txt, text inside the content, add space, and then use the command gzip compression and decompression process.
The experimental operation is as follows:
[[email protected] ~]# cd /tmp/ //First enter the TMP directory [[email protected] tmp]# ls // View files under directory 1.txt1.txt.gzaming.111aming2d6zsystemd-private-1a62fa1d021142a6a2c4311398e07768-vmtoolsd.service-jcwqlrsystemd-pri vate-6260bb09272b40ea93af94debf4ed36d-vmtoolsd.service-iebkctsystemd-private-75856aca996746b1b43ad52689f8adf1-vmtoolsd.se rvice-ffietisystemd-private-d7366ef92190425097a68c22ada7a3b0-vmtoolsd.service-lzzspvtestyum.log[[email protected] d6z]# gzip 1.txt //compress the text [[email protected] d6z]# ls //Viewing Files 1.txt.gz[[email protected] d6z]# du -sh 1.txt.gz //View compressed package size 332k1.txt.gz[[email protected] d6z]# gzip -d 1.txt.gz //Unpacking the Tarball [ [email protected] d6z]# du -sh 1.txt //unzip to view file size 1.3m1.txt[[email protected] d6z]# gzip -1 1. Txt //-1 refers to the compression level, the range 1-9, the default level is 6[[email protected] d6z]# du -sh 1.txt.gz //the file becomes larger after changing the compression level 392k1.txt.gz[[email protected] d6z]# file 1.txt.gz //Viewing compressed file information 1.txt.gz: gzip compressed data, was "1.txt", from unix, last modified: tue nov 7 19:38:56 2017, max speed[[email protected] d6z]# zcat 1.txt.gz //View Compressed file content Information 2, the compressed file does not replace the old text, directly generate a new compressed file to the specified directory, in the compressed file into a new text named file. The operation is as follows:[[email protected] d6z]# gzip -c 1.txt > /tmp/1.txt.gz //retains the original file and compresses the file to the specified directory [[email protected] d6z]# ls1.txt[[email protected] d6z ]# ls /tmp/1.txt.gz/tmp/1.txt.gz[[email protected] d6z]# file !$ //use the file command to view compressed file information File /tmp/1.txt.gz/tmp/1.txt.gz: gzip compressed data, was "1.txt", from unix, last modified: tue nov 7 19:38:56 2017[[email protected] d6z]# gzip -d -c /tmp/1.txt.gz > /tmp/d6z/2.txt //extract to generate a new text and specify which directory to extract and keep the compressed file [email protected] d6z]# ls1.txt 2.txt[[email protected] d6z]# wc -l 1.txt 2.txt32400 1.txt32400 2.txt64800 total dosage [[email protected] d6z]# du -sh *.txt1.3m1.txt1.3m2.txt
BZIP2 Compression Tool:
1. Install bzip2 tools Yum install-y bzip2
2, experiment, create a text 1.txt, using bzip2 compression, view the compressed file size, unzip the file, and then compress the text, using another way BUZIP2 decompression.
The experimental operation is as follows:
[[email protected] d6z]# ls //view files under directory 1.txt 2.txt[[email protected] d6z]# bzip2 1.txt //Compressed Files 1.txt[[email protected] d6z]# ls1.txt.bz2 2.txt[[email protected] d6z]# du -sh 1.txt.bz2 //view file size after compression 160k1.txt.bz2[[email protected] d6z]# bzip2 -d 1.txt.bz2 //unzip the file [[Email protected] d6z]# ls1.txt 2.txt[[email protected] d6z]# bzip2 1.txt //re-compression [[email protected] d6z]# bunzip2 1.txt.bz2 //a different way to unzip the
3, using the bzip2-c operation, as with gzip, you can specify compression into the directory and extract into a new text, BZIP2 also has the same compression level, the default level is 9, you can use the file command to view the files information
[[email protected] d6z]# bzip2 -c 1.txt > /tmp/1.txt.bz2 //retains the original file and compresses the file to the specified directory [[EMAIL PROTECTED] D6Z]# DU -SH /TMP/1. txt.bz2160k/tmp/1.txt.bz2[[email protected] d6z]# bzip2 -d -c /tmp/1.txt.bz2 > 3.txt //extracts a new text and specifies which directory to extract to and preserves the compressed file. [[email protected] d6z]# ls1.txt 2.txt 3.txt[[email protected] D6z]# du -sh 3.txt1.3m3.txt[[email protected] d6z]# bzip2 -9 1.txt //Specify level compression, default is 9[[email protected] d6z]# du -sh 1.txt.bz2160K1.txt.bz2[[email protected] d6z]# file 1.txt.bz2 //use the file command to view the compressed file information 1.txt.bz2: bzip2 compressed data, block size = 900k[[email protected] d6z]# bzcat 1.txt.bz2 // View compressed Files 1.txt.bz2 content information directly
question: What if you change the name of a compressed file to the wrong one?
[[email protected] d6z]# ls //View the file 1.txt.bz2 2.txt 3.txt[[email protected] d6z]# mv 1 in the directory. txt.bz2 1.txt //deliberately change the compressed file name to 1.txt[[email protected] d6z] # ls1.txt 2.txt 3.txt[[email protected] d6z]# less 1.txt //use less to view the 1.txt times wrong " 1.txt " may be a binary file. see it anyway? [[email protected] d6z]# file 1.txt //If this problem occurs, you can use the file command to view the text 1.txt1.txt: bzip2 compressed data, block size = 900k[[email protected] d6z]# file 2.txt //verification View, tell you this is a text file, you can use the Less 2.txt view 2.txt: c source, utf-8 unicode text, with very long lines[[email protected] d6z]# mv 1.txt 1.txt.bz2 //the experiment, correct the previously modified file [[email protected] d6z]# ls //return to normal 1.txt.bz2 2.txt 3.txt
XZ Compression Tool:
1, XZ Compression Tool command operation is the same as gzip and bzip2.
The experimental operation is as follows:
[[email protected] d6z]# ls1.txt.bz2 2.txt 3.txt[[email protected] d6z]# xz 2.txt //compressed files into xz[[email protected] d6z]# du -sh 2.txt.xz60k2.txt.xz[[email protected] d6z]# du -sh 3.txt1.3m3.txt[[email protected] d6z]# xz -d 2.txt.xz //Decompression [[email protected] d6z]# xz 2.txt //compression [[email protected] d6z]# unxz 2.txt.xz //another way to decompress [[email protected] d6z]# xz -c 2.txt > /tmp/2.txt.xz //keep the original file and compress the file to the specified directory [[email protected] d6z]# xz -d -c /tmp/2.txt.xz > ./4.txt // Unzip to generate a new text and specify which directory to extract to and keep the compressed file. [[email protected] d6z]# xzcat /tmp/2.txt.xz //direct view of compressed files 1.txt.bz2 content Information
Supplemental knowledge: gzip, BZIP2, XZ Three compression tools do not support compression of the directory
This article is from the "Gary Blog" blog, please be sure to keep this source http://taoxie.blog.51cto.com/10245493/1980412
Linux gzip, bzip2, XZ three ways to compress usage tool introduction