Linux Compressed package management 、 decompression 、 Compressed archive , Compression principle .


Compress and pack


Format Compression tool
.zip zip Compression tool
.gz gzip Compression tool , Only files can be compressed , Will delete the source file ( Usually cooperate tar Use )
.bz2 bzip2 Compression tool , Only files can be compressed , Will delete the source file ( Usually cooperate tar Use )
.tar.gz First use tar Order archiving and packaging , And then use gzip Compress
.tar.bz2 First use tar Order archiving and packaging , And then use bzip Compress


gzip


yum -y install gzip
Usage: gzip [OPTION]... [FILE]...
gzip  File name compression .
gzip
-d decompression
#  characteristic
1、 Only files can be compressed , Can't compress Directory
2、 After compression, the source file disappears
3、 After decompressing the file, the compressed package will disappear
4、 Multiple files gzip It's a single package file , Big compression ratio
5、 Use zcat  You can directly view the contents of the file
6、 Which path is the packaged file in , Just put the package in the directory where the source file is located
[[email protected] tmp]# gzip test.txt Create a compressed file
[[email protected] tmp]# gzip -d test.txt.gz  decompression
[[email protected] tmp]# zcat test.txt.gz see file 


zip


zip [-options] [filename] [zipfile list]
zip  The luggage   clothes
-r Package directory
-q The packaging process does not display output
1、zip Compressed files , The source file won't disappear .
2、zip After decompressing , If there is the same file name in the directory as in the compressed package , Ask if you want to overwrite
3、zip Compressed Directory , Without adding any parameters , You can only package empty directories , If you want to package the directory, you need to add  -r
4、 If you package the absolute path, you will package all the contents of the absolute path , And delete /, Package in which directory execution will be packaged in which directory .
#  notes :zip The purpose of compressing and deleting roots is to prevent covering .
file  file name   #  View file type
[[email protected] tmp]# zip test.zip test.txt Compressed package
[[email protected] tmp]# unzip test.zip  decompression
[[email protected] tmp]# zip -r etc.zip /etc Package directory 


tar


#  Archiving tools
Usage: tar [OPTION...] [FILE]...
tar You don't need to add  - 
-c Create a new archive
-x Unzip Archive
-f Specify the file name of the package , If it's multiple options ,f One point should be put at the end
-v Show the process
-z Use after filing gzip Compress
-P The operation on absolute path does not delete the root directory
-t View the compressed items in the compressed package
-C Specify the decompression path
-j bzip2
-J xz
-h Package soft links
-X Specify the excluded directory or file , Write the excluded file or directory to the file
--exclude=123 exclude 123 Specified file or directory
#  Be careful : The file will be overwritten when decompressing
[[email protected] tmp]# tar -czvf etc.tar.gz /etc establish tar.gz My bag
[[email protected] tmp]# tar -xzvf etc.tar.gz Unzip create tar.gz My bag
[[email protected] opt]# tar -xzvf etc.tar.gz -C /opt Specify the extraction Directory
[[email protected] tmp]# tar -czvPf etc1.tar.gz /etc Packing absolute paths
[[email protected] tmp]# tar -tf log.var.gz Look at the items in the compressed file
[[email protected] tmp]# tar -cjf log.tar.bz2 /var/log/ Compress tar.bz2
[[email protected] tmp]# tar -xf log.tar.bz2 decompression tar.bz2
[[email protected] tmp]# tar -cJf log.tar.xz /var/log/ Compress tar.xz
[[email protected] tmp]# tar -xf log.tar.xz decompression
[[email protected] tmp]# tar -czvf gd.tar.gz * --exclude=services Exclude files
[[email protected] tmp]# tar -czvf gd.tar.gz * --exclude=services --exclude=hosts
[[email protected] tmp]# tar -czvf gd.tar.gz -X /mnt/exc_list  * Specify the exclusion file