Linux compression and packaging command usage (1)

Source: Internet
Author: User

Tar command

[Root @ linux ~] # Tar [-cxtzjvfpPN] file and directory ....

Parameters:

-C: create a parameter command for the compressed file );

-X: Unlock the parameter command of a compressed file!

-T: view the files in the tarfile!

Note that c/x/t can only exist under the parameter! Cannot exist at the same time!

Because it is impossible to simultaneously compress and decompress.

-Z: does it have the gzip attribute at the same time? That is, do I need to use gzip for compression?

-J: Does it have bzip2 attributes at the same time? That is, do I need to use bzip2 for compression?

-V: The file is displayed during compression! This is common, but it is not recommended to use it in the background execution process!

-F: use the file name. Please note that the file name should be followed immediately after f! Do not add parameters!

For example, using "tar-zcvfP tfile sfile" is an incorrect method.

"Tar-zcvPf tfile sfile" is correct!

-P: the original property of the original file will not be changed based on the user)

-P: absolute paths can be used for compression!

-N: a new date (yyyy/mm/dd) will be packed into the new file!

-- Exclude FILE: do not pack the FILE during compression!

Example:

Example 1: package all the files in the/etc directory into/tmp/etc.tar

[Root @ linux ~] # Tar-cvf/tmp/etc.tar/etc

Gzip and zcat commands

[Root @ linux ~] # Gzip [-cdt #] File Name

[Root @ linux ~] # Zcat file name .gz

Parameters:

-C: outputs compressed data to the screen and can be processed through data stream redirection;

-D: extract parameters;

-T: it can be used to check the consistency of a compressed file ~ Check whether the file has any errors;

-#: Compression level.-1 is the fastest, but the compression ratio is the worst.-9 is the slowest, but the compression ratio is the best! Default Value:-6 ~

Example:

Example 1: copy/etc/man. config to/tmp and compress it with gzip

[Root @ linux ~] # Cd/tmp

[Root @ linux tmp] # cp/etc/man. config.

[Root @ linux tmp] # gzip man. config

# At this time, man. config will become man.config.gz!

Example 2: Read the content of Example 1!

[Root @ linux tmp] # zcat man.config.gz

# The man.config.gz extracted file content is displayed on the screen !!

Example 3: Decompress the file in Example 1

[Root @ linux tmp] # gzip-d man.config.gz

Example 4: compress man. config unlocked in Example 3 with the optimal compression ratio and keep the original file

[Root @ linux tmp] # gzip-9-c man. config> man.config.gz

Bzip2, bzcat command

[Root @ linux ~] # Bzip2 [-cdz] File Name

[Root @ linux ~] # Bzcat file name .bz2

Parameters:

-C: output the data generated during the compression process to the screen!

-D: extracted Parameters

-Z: Compression Parameters

-#: Same as gzip, it is used to calculate the compression ratio.-9 is the best, and-1 is the fastest!

Example:

Example 1: compress/tmp/man. config with bzip2

[Root @ linux tmp] # bzip2-z man. config

# At this time, man. config will become man.config.bz2!

Example 2: Read the content of Example 1!

[Root @ linux tmp] # bzcat man.config.bz2

# The man.config.bz2 extracted file content is displayed on the screen !!

Example 3: Decompress the file in Example 1

[Root @ linux tmp] # bzip2-d man.config.bz2

Example 4: compress man. config unlocked in Example 3 with the optimal compression ratio and keep the original file

[Root @ linux tmp] # bzip2-9-c man. config> man.config.bz2

Compress command

[Root @ linux ~] # Compress [-dcr] file or directory

Parameters:

-D: extract parameters.

-R: It can be compressed together with files in the directory!

-C: output compressed data to standard output (output to the screen)

Example:

Example 1: copy/etc/man. config to/tmp and compress it

[Root @ linux ~] # Cd/tmp

[Root @ linux tmp] # cp/etc/man. config.

[Root @ linux tmp] # compress man. config

[Root @ linux tmp] # ls-l

-Rw-r -- 1 root 2605 Jul 27 :43 man. config. Z


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.