Linux file compression and packaging

Source: Internet
Author: User

Common compressed packaging file tools under Linux are: gzip, bzip2, XZ, zip, and tar

Gzip Compression Tool:

Format: gzip [-d#] filename, where # is a number 1-9

-D: This parameter is used when decompressing

-#: Indicates the compression level, 1 is the worst, 9 is the best, the default is 6.

-C: Keep source files when compressing

Compression: gzip 1.txt; compress 1.txt, file 1.txt disappears, generate 1.txt.gz

Decompression: gzip-d 1.txt.gz; gzip-d ==gunzip

View. GZ compressed Files: Zcat 1.txt.gz

"Note: gzip does not support compressed directories"

BZIP2 Compression Tool:

Format: bzip2 [-dz] filename, where-D: decompression,-Z: Compression, BZIP2 also has 1-9 compression levels, default level is 9

Compression: bzip2 1.txt;bzip2 Compressed source files will also disappear; (-C: Preserve source files when compressing)

Decompression: bzip2-d 1.txt.bz2; bzip2-d ==bunzip2

View. bz2 compressed Files: Bzcat 1.txt.bz2

"Note: Bzip2 also does not support compressed directories"

XZ Compression Tool:

Format: XZ [-dz] filename; similar to bzip2,-Z: compression,-D compression; default level is 6

Compression: XZ 1.txt; source file disappears; (-C: Preserves source files when compressing)

Decompression: xz-d 1.txt.xz; xz-d ==unxz

View. xz File: Xzcat 1.txt.xz

"Note: XZ also does not support compressed catalogs"

Zip compression tool:

Zip compression in Windows and Linux are more commonly used, it can compress files and directories, compressed directory, you need to specify directory path files, for example: Zip 1.txt.zip 1.txt

If you do not have a zip command, you need to install it: Yum install-y zip, and of course unzip needs Yum install-y unzip installation

Compression: Zip Test.zip test/*; -R: Implementing Multilevel Directory Compression

Decompression: Unzip Test.zip; Use-D to specify the extracted storage directory, such as unzip 1.zip-d/tmp

"Note: the. zip file is not able to view the contents of the file, but can view the file list of compressed files, the command is Unzip-l test.zip"

Tar Packaging tools:

Tar itself is a packaging tool that can package a directory into a file that synthesizes all the files into a large file for easy movement or duplication.

Format: tar [-ZJXCVFPP] filename

-Z: Indicates simultaneous use of gzip compression

-j: Indicates simultaneous use of bzip2 compression

-j: Indicates simultaneous use of XZ compression

-X: Means unpacking or decompressing

-T: Indicates viewing files in the TAR package

-C: means to build a tar package or to compress a file package

-V: Represents a visualization

-F: followed by file name (that is,-f filename)

-P: Indicates the use of the original file's properties (not commonly used)

-P: Indicates that an absolute path can be used (not commonly used)

--exclude filename: Do not include the filename file when packaging or compressing (infrequently used)

Packing directory: TAR-CVF 123.tar 123/

Package files and directories simultaneously: TAR-CVF 123.tar 1.txt 123/

Unpacking: TAR-XVF 123.tar

View package files: TAR-TF 123.tar

Filter files or directories when packaging: TAR-CVF 123.tar--excude 1.txt--exclude 123/

Package and Compress files simultaneously (unzip):

TAR-ZCVF 123.tar.gz 123/; TAR-ZXVF 123.tar.gz;

TAR-JCVF 123.tar.bz2 123/; TAR-JXVF 123.tar.bz2;

TAR-JCVF 123.TAR.XZ 123/; TAR-JXVF 123.tar.xz;


Linux file compression and packaging

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.