Linux file Packaging and compression

Source: Internet
Author: User

in the Linux There are a lot of supported compression commands, and the extension of common compressed files is *.gz , *.bz2 , *.tar.gz , *.tar.bz2 and so on. Compression decompression is a very common function, but the command parameters are slightly more complex, so a few common usage to make a simple summary.


1.gzip

< Span style= "font-family: ' Liberation Serif ', Serif" >      gzip gnuzip is a very good file compression program. In addition to *.gz file, gzip can also be used to decompress *.zip , *. A compressed file in a format such as Z . and *.gz files can also be used winrar decompression, easy to use. Here are some common


gzip-option filename

- C : Displays the results of the compression to the screen, the original file is unchanged, you can write the results to a file via data flow redirection.

- D : Unzip

-F : force overwrite old file

- L : lists the original files stored in the compressed package, the extracted name, the compression rate, and so on. Note Adding- l will not decompress even if the- D parameter is

- R : recursively compress all files in directory

- T : Testing the integrity of compressed files

- v : Show Compression ratio

-1~9 : compression level, the larger the number, the smaller the pressure, the slower the speed, the default level is 6


gunzip-option filename

The decompression command, equivalent to gzip-d. can use the same parameters and gzip , of course, less than- D, also can not set a level.


Zcat-filename

View the contents of a compressed file


2.bzip2

< Span style= "font-family: ' Liberation Serif ', Serif" >        bzip2 is a burrows-wheeler Transform lossless compression software, which has a compression ratio of bzip2 usage and gzip basically the same, the parameters mentioned above can be inherited (except for -l means License ). Here are some common parameters


bzip2-option filename

- k : Keep the original file

-s : Use less memory


bunzip2-option filename

The decompression command, equivalent to bzip2-d.


Bzcat-filename

View the contents of a compressed file


bzip2 Recover

Recovering data from a corrupted *.bzip2 file


3.tar

The commands mentioned above can only be compressed for a single file. Although you can add the- r parameter to compress the directory, only the individual files under the directory are compressed separately, and eventually the directory remains. To compress a folder into a compressed package. Then you will use the tar command. The role of tar is to package multiple files or directories. There are many tar commands, and here are some common ones.



tar-option filename

-C : Create a new packaged file

-D : diff Files and files in the tar package

-T : See what files are included in the packaged file

-X : unpacking or decompressing

-J : compression / decompression using bzip2

-Z : compression / decompression using gzip

-R : Add a new file to the tar package

-A : Add an existing tar package to another tar package

-K : do not overwrite existing files on the system

-V : Displays the file name being processed

-P : preserves the original permissions and properties of the file

-F : The file name to be processed

- C : Specify the directory when extracting

--exclude=filename : does not include the filename when packaging

The usual use can be summed up in the following modes:

Query: tar-j (z) TVF filname

Compression: tar-j (z) cvf file name to compress for new file name

Decompression: tar-j (z) xvf file name to extract - c extract the directory


PS: Note that the tar does not automatically generate a file suffix, so the new file name needs to be added to its own suffix for easy identification. And also

The- F parameter must be placed at the end with the file name attached, or independently to prevent errors.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux file Packaging and compression

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.