Introduction to the zip and tar compression packaging tools for Linux

Source: Internet
Author: User
Tags bz2

Zip compression tool:


1. Install the zip command tool Yum install-y zip

2, zip compression tool can be compressed files can also compress the directory, and compression will not be deleted source files, examples are as follows:

[[email protected] d6z]# ls                  //View the files under the directory 1.txt.bz2  2.txt  3.txt  4.txt   aminglinux[[email protected] d6z]# zip 2.txt.zip 2.txt          //using zip compression 2.txtadding: 2.txt  (deflated 74%) [[email  protected] d6z]# ls                               // View compression Complete 1.txt.bz2  2.txt  2.txt.zip  3.txt  4.txt  aminglinux[ [email protected] d6z]# du -sh 2.txt.zip                 //viewing the compression size 332k2.txt.zip[[email protected] d6z]#  ls1.txt.bz2  2.txt  2.TXT.ZIP  3.TXT  4.TXT  AMINGLINUX[[EMAIL PROTECTED] D6Z] # zip -r aming.zip 3.txt aminglinux      //zip - R compress both text and directory adding: 3.txt  (deflated 74%) adding: aminglinux/  (stored 0%) adding:  aminglinux/1.txt  (stored 0%) adding: aminglinux/2/  (stored 0%) adding:  aminglinux/2/4.txt  (deflated 74%) [[Email protected] d6z]# ls1.txt.bz2  2. Txt  2.txt.zip  3.txt  4.txt  aminglinux  aming.zip[[email  protected] d6z]# du -sh aming.zip664kaming.zip[[email protected] d6z]#  unzip-bash: unzip:  no command found [[email protected] d6z]# yum install -y  unzip              //installing the Unzip command Unzip[[email  protected] d6z]# unzip aming.zip                  //Decompression Archive:  aming.zipreplace 3.txt? [y]es, [n]o, [a]ll,  [N]one, [r]ename: n                   //because the compressed time does not delete the source files, at the time of decompression will be accessed if you need to overwrite. replace aminglinux/1.txt?  [y]es, [n]o, [a]ll, [n]one, [r]ename: yextracting: aminglinux/1.txtreplace  aminglinux/2/4.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: aerror:   invalid response [a]replace aminglinux/2/4.txt? [y]es, [n]o, [a]ll, [ n]one, [r]ename: a    //big A is decompression all inflating: aminglinux/2/4.txt

Example: compressing to the specified directory using unzip

[[email protected] d6z]# ls1.txt.bz2  2.txt   2.txt.zip  3.txt  4.txt  aminglinux  aming.zip[[email  protected] d6z]# mkdir test                     //Create a new directory [[email protected] d6z]#  unzip 2.txt.zip -d test/                      //compression to the test directory archive:  2.txt.zipinflating : test/2.txt[[email protected] d6z]# unzip 2.txt.zip -d test/aa.txt         //Specifies the compressed file name error archive:  2.txt.zip inflating: test/ aa.txt/2.txt          //description, the file name before compression is what is and cannot be changed. 

In the following, the ZIP package cannot view the contents directly, only the file list of the compressed package. Examples are as follows:

[Email protected] d6z]# unzip-l aming.zipArchive:aming.zipLength Date time Name------------------------ ----1286145 11-08-2017 19:51 3.txt0 11-08-2017 20:51 aminglinux/0 11-08-2017 20:46 aminglinux/1.txt0 11-08-201                     7 20:51 aminglinux/2/1286145 11-08-2017 20:51 aminglinux/2/4.txt----------------2572290 5 files


Tar Packaging tools:


Command usage:

1,TAR-CVF aminglinux.tar aminglinux///Create packaged files

2, tar-cvf aminglinux.tar aminglinux 3.txt 4.txt//Create package directory plus file

3,TAR-XVF Aminglinux.tar//Unpacking

4,TAR-TF Aminglinux.tar//View a list of directories for a compressed package

5, TAR-CVF Aminglinux.tar --exclude 2 aminglinux 3.txt 4.txt//filter The specified directory or file, support the wildcard


The experimental operation is as follows:

[[Email protected] d6z]# ls1.txt.bz2  2.txt  2.txt.zip  3.txt   4.txt  aminglinux  aming.zip  test[[email protected] d6z]#  tar -cvf aminglinux.tar aminglinux/     //using tar - CVF This command to pack Aminglinux/aminglinux/2/aminglinux/2/4.txtaminglinux/1.txt[[email protected] d6z]# tar  -cf aminglinux.tar aminglinux/     //shows the packaging process without V, repackaging the same file, overwriting the previously packaged file directly , without prompting. [[Email protected] d6z]# ls1.txt.bz2  2.txt  2.txt.zip  3.txt   4.txt  aminglinux  aminglinux.tar  aming.zip  test[[email  protected] d6z]# tar -xvf aminglinux.tar             //is also overwritten before the file is not prompted. aminglinux/aminglinux/2/aminglinux/2/4.txtaminglinux/1.txt[[email protected] d6z]# tar -cvf aminglinux.tar aminglinux 3.txt 4.txt  // Package directory plus file aminglinux/aminglinux/2/aminglinux/2/4.txtaminglinux/1.txt3.txt4.txt[[email protected] d6z] # tar -tf aminglinux.tar  //view file list AMINGLINUX/AMINGLINUX/2/AMINGLINUX/2/4. txtaminglinux/1.txt3.txt4.txt[[email protected] d6z]# tar -cvf aminglinux.tar -- exclude 2 aminglinux 3.txt 4.txtaminglinux/aminglinux/1.txt3.txt4.txt[[email  Protected] d6z]# tar -cvf aminglinux.tar --exclude 2 --exclude 1.txt  aminglinux 3.txt 4.txtaminglinux/3.txt4.txt


Tar Package and compress:


    1. TAR-CZVF aminglinux.tar.gz aminglinux 3.txt 4.txt//gz packaged and compressed

    2. TAR-XZVF aminglinux.tar.gz aminglinux 3.txt 4.txt//gz unpacking and decompression

    3. TAR-CJVF aminglinux.tar.bz2 aminglinux 3.txt 4.txt//bz2 packaged and compressed

    4. TAR-XJVF aminglinux.tar.bz2 aminglinux 3.txt 4.txt//bz2 unpacking and decompression

    5. TAR-CJVF aminglinux.tar.xz aminglinux 3.txt 4.txt//xz2 packaged and compressed

    6. TAR-XJVF aminglinux.tar.xz aminglinux 3.txt 4.tx//xz2 unpacking and decompression

    7. TAR-TF aminglinux.tar.gz//gz View a list of files for a compressed package

    8. TAR-TF aminglinux.tar.xz//xz View a list of files for a compressed package

    9. TAR-TF aminglinux.tar.bz2//bz2 View a list of files for a compressed package


The

Experiment operates as follows:

[[email protected] d6z]# tar -czvf aminglinux.tar.gz aminglinux 3.txt  4.txtaminglinux/aminglinux/2/aminglinux/2/4.txtaminglinux/1.txt3.txt4.txt[[email protected] d6z]#  du -sh aminglinux.tar.gz992Kaminglinux.tar.gz[[email protected] d6z]# tar  -cjvf aminglinux.tar.bz2 aminglinux 3.txt 4.txtaminglinux/aminglinux/2/aminglinux/2/4. txtaminglinux/1.txt3.txt4.txt[[email protected] d6z]# du -sh  aminglinux.tar.bz2392kaminglinux.tar.bz2[[email protected] d6z]# tar -cjvf  Aminglinux.tar.xz aminglinux 3.txt 4.txtaminglinux/aminglinux/2/aminglinux/2/4.txtaminglinux/1. txt3.txt4.txt[[email protected] d6z]# du -sh aminglinux.tar.xz60kaminglinux.tar.xz[[ email protected] d6z]# ls1.txt.bz2  2.txt.zip  4.txt        aminglinux.tar      aminglinux.tar.gz  aming.zip2.txt      3.txt       aminglinux  aminglinux.tar.bz2  aminglinux.tar.xz   test[[email protected] d6z]# tar -tf aminglinux.tar.gzaminglinux/aminglinux/2/ aminglinux/2/4.txtaminglinux/1.txt3.txt4.txt[[email protected] d6z]# tar -tf  Aminglinux.tar.xzaminglinux/aminglinux/2/aminglinux/2/4.txtaminglinux/1.txt3.txt4.txt[[email protected]  d6z]# tar -tf aminglinux.tar.bz2aminglinux/aminglinux/2/aminglinux/2/4.txtaminglinux/1. Txt3.txt4.txt

Knowledge Points: Zip has a feature, after compressing the file, the original file is not deleted, and gzip, bzip2, XZ three kinds of compression after the original file is deleted.


This article is from the "Gary Blog" blog, please be sure to keep this source http://taoxie.blog.51cto.com/10245493/1980763

Introduction to the zip and tar compression packaging tools for Linux

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.