Summary of commonly used compression tools under Linux (Gzip/tar/bzip2/zip)

Source: Internet
Author: User
Tags bz2 mcrypt syslog zip extension

Gzip:

1) only for ordinary files compression, folder, Symbolic link is not valid.

2) If you want to compress and package multiple files together, Gzip is not possible and need to be combined with tar

[[email protected] databackup]# ll total dosage 32drwx------2 root root 4096 October 00:43 2016-10-12_00-43-29drwx------2 root root 4096 October 00:44 2016-10-12_00-44-00drwx------2 root root 4096 October 00:46 2016-10-12_00-46-53drwx------2 root root 4 096 October 00:47 2016-10-12_00-47-43drwx------2 root root 4096 October 00:49 2016-10-12_00-49-02-rw-r--r--1 root root 252 2 October 21:17 passwddrwxr-xr-x 2 root root 4096 October 00:37 xtrabackupdrwxr-xr-x 2 root root 4096 October 00:37 Xtrabacku Plog

With the "-C" option, you can keep the original file

[[email protected] databackup]# gzip -c passwd >passwd.gz[[email  Protected] databackup]# ll Total dosage  36drwx------ 2 root root 4096 10 Month   12 00:43 2016-10-12_00-43-29DRWX------ 2 root root 4096 10 Month  12  00:44 2016-10-12_00-44-00DRWX------ 2 root root 4096 10 Month  12 00:46  2016-10-12_00-46-53DRWX------ 2 root root 4096 10 Month  12 00:47  2016-10-12_00-47-43DRWX------ 2 root root 4096 10 Month  12 00:49 2016-10-12 _00-49-02-rw-r--r-- 1 root root 2522 10 Month  19 21:17 passwd-rw-r--r--  1 root root 1006 10 Month  19 21:18 passwd.gzdrwxr-xr-x 2 root  root 4096 10 Month  12 00:37 xtrabackupdrwxr-xr-x 2 root root  4096 10 Month  12 00:37 xTrabackuplog 

The gzip+ file is compressed directly, and the original file is not retained

[[email protected] databackup]# cp /etc/shadow . [[email protected] databackup]# ll Total dosage  40drwx------ 2 root root 4096  10 month  12 00:43 2016-10-12_00-43-29drwx------ 2 root root 4096 10 Month  12 00:44 2016-10-12_00-44-00DRWX------ 2 root root 4096 10 Month  12  00:46 2016-10-12_00-46-53DRWX------ 2 root root 4096 10 Month  12  00:47 2016-10-12_00-47-43DRWX------ 2 root root 4096 10 Month  12 00:49  2016-10-12_00-49-02-rw-r--r-- 1 root root 2522 10 Month  19 21:17  Passwd-rw-r--r-- 1 root root 1006 10 month  19 21:18 passwd.gz----------  1 root root 1393 10 Month  19 21:19 shadowdrwxr-xr-x 2 root  Root 4096 10 Month  12 00:37 XTRABACKUPDRWXR-XR-X&NBsp;2 root root 4096 10 month  12 00:37 xtrabackuplog[[email protected] Total dosage of  databackup]# gzip shadow [[email protected] databackup]# ll   40DRWX------ 2 root root 4096 10 Month  12 00:43 2016-10-12_ 00-43-29DRWX------ 2 root root 4096 10 Month  12 00:44 2016-10-12_ 00-44-00DRWX------ 2 root root 4096 10 Month  12 00:46 2016-10-12_ 00-46-53DRWX------ 2 root root 4096 10 Month  12 00:47 2016-10-12_ 00-47-43DRWX------ 2 root root 4096 10 Month  12 00:49 2016-10-12_00-49-02- Rw-r--r-- 1 root root 2522 10 Month  19 21:17 passwd-rw-r--r-- 1  Root root 1006 10 Moon  19 21:18 passwd.gz---------- 1 root root   536 10 Month  19 21:19 shadow.gzdrwxr-xr-x 2 root root 4096 10 Month  12 00:37 xtrabackupdrwxr-xr-x 2 root  Root 4096 10 Month  12 00:37 xtrabackuplog

Use "gzip-d compressed file" to extract

[[email protected] databackup]# gzip -d shadow.gz[[email protected]  Databackup]# ll Total dosage  40drwx------ 2 root root 4096 10 Month  12 00:43  2016-10-12_00-43-29DRWX------ 2 root root 4096 10 Month  12 00:44  2016-10-12_00-44-00DRWX------ 2 root root 4096 10 Month  12 00:46 2016-10-12 _00-46-53DRWX------ 2 root root 4096 10 Month  12 00:47 2016-10-12_ 00-47-43DRWX------ 2 root root 4096 10 Month  12 00:49 2016-10-12_00-49-02- Rw-r--r-- 1 root root 2522 10 Month  19 21:17 passwd-rw-r--r-- 1  Root root 1006 10 Moon  19 21:18 passwd.gz---------- 1 root root  1393 10 Month  19 21:19 SHADOWDRWXR-XR-X 2 ROOT ROOT 4096 10 Month  12  00:37 xtrabackupdrwxr-xr-x&Nbsp;2 root root 4096 10 month  12 00:37 xtrabackuplog As above, we found that the original shadow file has come out 

Gzip has nine compression level 1-9 (the larger the number, the higher the compression strength, the slower the speed corresponds), the default level is 6

# gzip-1 Test.log


Tar

Compress/etc files: [[email protected] databackup]# TAR-CZVF etc.tar.gz/etc[[email protected] databackup]# du-sh etc.tar.gz 12Metc . tar.gz unzip and view [[email protected] databackup]# TAR-XF Etc.tar.gztar frequently used options:-C option: Represents the action to be packaged by the-X option: Indicates that you want to unpack the action-Z option: Compress or decompress with gzip-V option: Indicates the entire process during the unpacking process and displays the unpacked file as-F option: Specifies the file to be unpacked-t option: Column Packaged content for situations where you don't want to unzip but want to see the contents of the compressed package [[email protected] databackup]# du-sh src.tar.gz 607msrc.tar.gz[[email protected] databackup]# TAR-ZTVF src.tar.gz |less



BZIP2:

Bzip2 for compressing files, bunzip2 for extracting files

But we look at the link file, will find that, in fact, BUNZIP2 is actually a link to bzip2

[[email protected] ~]# ls -l /usr/bin/bunzip2 lrwxrwxrwx. 1 root  Root 5 7 Month    5 23:42 /usr/bin/bunzip2 -> bzip2[[email  protected] ~]# bzip2 install.log[[email protected] ~]# lsanaconda-ks.cfg         index.html        install.log.syslog  m_pass.log  r_server.log   templates    Pictures    Downloads    Desktop changehostpassword.sh  install.log.bz2  ip_list.txt          R_PWD.txt    Public          Videos    Documentation    Music [[email protected] ~]# file install.log.bz2  install.log.bz2: bzip2 compressed data, block size = 900k[[email  Protected] ~]# bunzip2 -d install.log.bz2 [[email protected] ~]# lsanaconda-ks.cfg         index.html   install.log.syslog  M_pass.log  R_Server.log   Templates    pictures    downloads    Desktop Changehostpassword.sh  install.log  ip_ list.txt         r_pwd.txt    Public           Videos    Documents    Music

Zip:

Similar to GZIP/BZIP2, zip is used for file compression, the unzip command is used for decompression, zip supports compression of files and folders,-R represents recursion

Note: Zip will keep the original file when compressing the file.

[[email protected] ~]# cd /usr/local/src/[[email protected] src]#  lscmake-2.8.8         libiconv-1.14.tar.gz     mcrypt-2.6.8         mhash-0.9.9.9.tar.gz                  mysql-5.5.32.tar.gz   php-5.3.27cmake-2.8.8.tar.gz  libmcrypt-2.5.8          mcrypt-2.6.8.tar.gz  mysql-5.5.32                          nginx-1.6.2           php-5.3.27.tar.gzlibiconv-1.14        libmcrypt-2.5.8.tar.gz  mhash-0.9.9.9         mysql-5.5.32-linux2.6-x86_64.tar.gz  nginx-1.6.2.tar.gz[[email protected] src]# zip -r nginx.zip  nginx-1.6.2.tar.gz nginx-1.6.2/[[email protected] src]# lscmake-2.8.8          libiconv-1.14.tar.gz    mcrypt-2.6.8          mhash-0.9.9.9.tar.gz                  mysql-5.5.32.tar.gz  nginx.zipcmake-2.8.8.tar.gz   libmcrypt-2.5.8         mcrypt-2.6.8.tar.gz   mysql-5.5.32                          nginx-1.6.2           php-5.3.27libiconv-1.14        Libmcrypt-2.5.8.tar.gz  mhash-0.9.9.9        mysql-5.5.32-linux2.6-x86_64.tar.gz   nginx-1.6.2.tar.gz   php-5.3.27.tar.gz[[email protected] src]# du -sh  Nginx.zip 7.7mnginx.zip

Unzip with the-D parameter, unzip to the specified folder

[Email protected] src]# mkdir-p/mysqlbackup[[email protected] src]# unzip-d/mysqlbackup nginx.zip [[email protected] src]# ls-l/mysqlbackup/Total dosage 792drwxr-xr-x 9 root root 4096 September nginx-1.6.2-rw-r--r--1 root root 804164 June 22 01:17 nginx-1.6.2.tar.gz

Use the combination of "Unzip-v compressed Files" To view the contents of a compressed file without being under pressure

[[email protected] src]# unzip -v nginx.zip archive:  nginx.zip  length   method    size  cmpr    date     time   crc-32   name--------  ------  ---- --- ---- ---------- ----- --------  ----  804164  defl:n    804176   0% 06-22-2016 01:17 c721c245   nginx-1.6.2.tar.gz       0  stored         0   0% 09-16-2014 20:23 00000000  nginx-1.6.2/     2369  defl:n      732  69% 09-16-2014  20:23 85d03809  nginx-1.6.2/configure       0   stored        0   0% 09-22-2016 15:46 00000000   nginx-1.6.2/contrib/       0  stored         0   0% 09-16-2014 20:23 00000000  nginx-1.6.2/ contrib/vim/       0  stored         0   0% 09-22-2016 15:46 00000000  nginx-1.6.2/contrib/vim/ indent/     250  defl:n      165   34% 09-16-2014 20:23 87c1f91b  nginx-1.6.2/contrib/vim/indent/nginx.vim        0  Stored        0    0% 09-22-2016 15:46 00000000  nginx-1.6.2/contrib/vim/ftdetect/      198  Defl:n       79  60% 09-16-2014 20:23 68d244f2   nginx-1.6.2/contrib/vim/ftdetect/nginx.vim       0   stored        0   0% 09-16-2014 20:23  00000000  nginx-1.6.2/contrib/vim/syntax/   31641  defl:n      5987  81% 09-16-2014 20:23 fe4d7202  nginx-1.6.2/contrib/vim/ syntax/nginx.vim       0  stored         0   0% 09-22-2016 15:46 00000000  nginx-1.6.2/ contrib/unicode2nginx/

Use Unzip-t compressed file to verify the integrity of the compressed file

[[email protected] src]# unzip -t nginx.zip archive:  nginx.zip     testing: nginx-1.6.2.tar.gz       OK     testing: nginx-1.6.2/              OK    testing: nginx-1.6.2/configure    OK     testing: nginx-1.6.2/contrib/     ok    testing:  nginx-1.6.2/contrib/vim/   ok    testing: nginx-1.6.2/contrib/ Vim/indent/   ok    testing: nginx-1.6.2/contrib/vim/indent/nginx.vim    OK    testing: nginx-1.6.2/contrib/vim/ftdetect/    ok    testing: nginx-1.6.2/contrib/vim/ftdetect/nginx.vim   ok     testing: nginx-1.6.2/contrib/vim/syntax/   ok    testing: nginx-1.6.2/ contrib/vim/syntax/nginx.vim   ok    testing: nginx-1.6.2/contrib/ unicode2nginx/   ok    testing: nginx-1.6.2/contrib/unicode2nginx/ koi-utf   ok    -------------------------------------------------------     -------------------------------------------------------    testing :  nginx-1.6.2/makefile     ok    testing: nginx-1.6.2/ conf/        ok    testing: nginx-1.6.2/conf/ uwsgi_params   ok    testing: nginx-1.6.2/conf/koi-utf    OK    testing: nginx-1.6.2/conf/win-utf   OK     testing: nginx-1.6.2/conf/mime.types   ok    testing: nginx-1.6.2/conf/fastcgi.conf    OK    testing: nginx-1.6.2/conf/koi-win   OK     testing: nginx-1.6.2/conf/fastcgi_params   ok    testing:  nginx-1.6.2/conf/scgi_params   ok    testing: nginx-1.6.2/conf/ nginx.conf   okno errors detected in compressed data of  Nginx.zip.

Zip extension:

When we configure the compressed file, we find that one of the more space-occupying files is not what we want, and we do not want to re-unzip and compress.

To delete a file to a compressed file: [[email protected] src]# zip nginx.zip-d nginx-1.6.2.tar.gz deleting:nginx-1.6.2.tar.gz[[email protected] src]# unzip-v nginx.zip |grep nginx-1.6.2.tar.gz found no file exists to add files to the compressed file: [[email protected] src]# zip-m nginx.zip nginx-1.6  .2.tar.gz adding:nginx-1.6.2.tar.gz (deflated 0) [[email protected] src]# unzip-v nginx.zip |grep nginx-1.6.2.tar.gz 804164 defl:n 804176 0% 06-22-2016 01:17 c721c245 nginx-1.6.2.tar.gz








This article is from the "Frozen vs watermelon" blog, so be sure to keep this source http://molewan.blog.51cto.com/287340/1863756

Summary of commonly used compression tools under Linux (Gzip/tar/bzip2/zip)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.