Linux Learning Notes (20) file compression zip compression, tar package, package, unpack

Source: Internet
Author: User
Tags bz2 unpack

One, zip compression

Install Zip and unzip first
Yum Install-y Zip/unzip

zip 1.txt.zip  1.txt

Compressed file 1.txt, compressed filename is called 1.txt.zip

 zip -r 123.zip  123/

Compressed folder 123/specified name 123.zip

 unzip 1.txt.zip

The zip file does not delete the source file and will prompt you to overwrite the existing file when extracting it.

Unzip the 123.zip file into the/root/456/directory

 unzip -l 123.zip

View a list of files in compressed file 123.zip

Ii. Tar Packaging tools

The TAR command creates archives for Linux files and directories. With tar, you can create files (backup files) for a specific file, or you can change files in the file or add new files to the file. Tar was originally used to create archives on tape, and now users can create files on any device. With the tar command, you can package a whole bunch of files and directories into a single file, which is useful for backing up files or combining several files into one file for easy network transmission.

The first thing to understand is two concepts: packaging and compression. Packaging refers to a large number of files or directories into a total file, compression is a large file through some compression algorithm into a small file.

Why should we differentiate between these two concepts? This is due to the many compression programs in Linux that can only be compressed for one file, so that when you want to compress a lot of files, you have to first make a package (Tar command) of the whole bunch of files, and then compress the program (gzip bzip2 command).

tar -cvf 123.tar 123

Package Directory 123/123.tar If the file already exists there will be no prompt (as no hint when unpacking), overwriting by default

 tar -cvf 123.tar 1.txt 123

File 1.txt and folder 123/package 123.tar

 tar -xvf 123.tar

Unpacking 123.tar

View a list of files in 123.tar
TAR-CVF 123.tar--exclude 1.txt--exclude 2 123
Package directory 123, exclude files 1.txt and 2
Files to be excluded can only be used with--exclude + file name
And a--exclude can only follow a file name or directory name, you can also use "*.txt"
This wildcard is a TXT file

Http://man.linuxde.net/tar, here's a more detailed introduction.

Three, packaging and compression
tar -zcvf 123.tar.gz 123

Package directory 123 and compress to GZ format

 tar -zxvf 123.tar.gz

Unpacking packages in GZ format

 tar -jcvf 123.bz2  123

Package and Compress folders into bz2 format

 tar -jxvf 123.bz2

Unpack

 tar -Jcvf 123.xz 123

Package and Compress folders into the XZ format

 tar -Jxvf 123.xz

J Unpacking

 tar -tf 123.bz2 / tar -tf 123.gz / tar -tf 123.xz

You can use TAR-TF to view the list of files in a compressed package, regardless of which compression format is packaged

Linux Learning Notes (20) file compression zip compression, tar package, package, unpack

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.