Network most comprehensive Linux compression and decompression commands Daquan __linux

Source: Internet
Author: User
Tags bz2 rar unpack
Network most comprehensive Linux compression and decompression commands DaquanDirectory Technology Article July 28, 2016

Compression and decompression commands, Linux is more commonly used in the command. Before the use of compression and decompression, are temporary online search, used after a period of time is useless to forget. Although the use of commands is easy to search on the Internet, but every time you use to search, it is a waste of time. So, here is a Linux compression and decompression command encyclopedia, a more in-depth study and grasp the use of these commands.

Compression and decompression are more common, because of the benefits of file compression: Reduce storage space, reduce file transfer time. For a larger number of files, in order to reduce storage space and transmission time, in addition to the use of compression, but also involves packaging. Note that compression and packaging are two different concepts: packaging is the packaging of a large number of files or directories into a single file (many-to-many); Compression is a large file compressed into a small file (one-to-one). When you compress a large number of files, you need to use the packaging tool to make all the files into a package, and then use the compression tool to compress the package.

The most common compressed file format under Windows is only zip and rar two, but the compressed file format under Linux is GZ, tar.gz, tgz, tar.bz2, tbz2, bz2, tar, zip, and rar. However, both zip and rar windows are the most common compressed file formats that are rarely used under Linux. If the Linux compression and decompression commands are unfamiliar, it is easy to be a large number of compressed file format to frighten dizzy. The following example describes the common compression and decompression commands in Linux. Examples are as follows:

[Root@linux tmp]# ls

Test1.txt Test2.txt Test3.txt

[Root@linux tmp]# Cat Test1.txt

Hello, test1!.

[Root@linux tmp]# Cat Test2.txt

Hello, test2!.

[Root@linux tmp]# Cat Test3.txt

Hello, test3!.

1. Gzip

GZIP Program compressed files to the end of. GZ, and its corresponding decompression program is gunzip, can also use gzip-d decompression.

Gzip Common parameter Description:

-C: Output compressed data to the screen

-D: Decompression

-R: Recursive compressed folder

-T: Verifying consistency of a compressed file

-1: The fastest compression, compression ratio is the worst

-9: The slowest compression, compression ratio best compression: gzip file

[Root@linux tmp]# gzip Test1.txt

[Root@linux tmp]# ls

test1.txt.gz test2.txt test3.txt Decompression 1:gunzip file.gz

[Root@linux tmp]# gunzip test1.txt.gz

[Root@linux tmp]# ls

Test1.txt test2.txt test3.txt Decompression 2:gzip-d file.gz

[Root@linux tmp]# gzip-d test1.txt.gz

[Root@linux tmp]# ls

Test1.txt test2.txt test3.txt Zcat extract to standard output:

[Root@linux tmp]# Zcat test1.txt.gz

Hello, test1!.

[Root@linux tmp]# ls

Test1.txt.gz Test2.txt Test3.txt

2. bzip2

BZIP2 Program compressed files to the. bz2 end, and its corresponding decompression program is BUNZIP2, can also use bzip2-d decompression.

BZIP2 commonly used parameter description:

-C: Output compressed data to the screen

-D: Decompression

-T: Verifying consistency of a compressed file

-1: The fastest compression, compression ratio is the worst

-9: Compression is the slowest, compression ratio best compression: bzip2 file

[Root@linux tmp]# bzip2 Test1.txt

[Root@linux tmp]# ls

test1.txt.bz2 test2.txt test3.txt Decompression 1:bunzip2 file.bz2

[Root@linux tmp]# bunzip2 test1.txt.bz2

[Root@linux tmp]# ls

Test1.txt test2.txt test3.txt Decompression 2:bzip2-d file.bz2

[Root@linux tmp]# bzip2-d test1.txt.bz2

[Root@linux tmp]# ls

Test1.txt test2.txt test3.txt Bzcat extract to standard output:

[Root@linux tmp]# bzip2 Test1.txt

[Root@linux tmp]# ls

TEST1.TXT.BZ2 Test2.txt Test3.txt

[Root@linux tmp]# Bzcat test1.txt.bz2

Hello, test1!.

[Root@linux tmp]# ls

TEST1.TXT.BZ2 Test2.txt Test3.txt

3. Tar

The TAR program can be packaged and unpacked. At the same time, in the packaging can be invoked through the operation of the parameters of the gzip or BZIP2 compression program compression, in the decompression can also be invoked through the operation parameters Gunzip or BUNZIP2 decompression program for decompression. On the surface, the program also has the function of packing compression and decompression unpack, so it is a very common command.

Operation Parameters:

-a,–catenate,–concatenate to merge an archive with an existing archive

-c,–create to create a new archive

-d,–diff,–compare comparison archive differs from current file

-r,–append attached to archive end

-t,–list lists the directories of files in the archive

-u,–update only append newer files to the archive

-x,–extract,–get Expand files from archive

These seven commands can only be selected when compressing or decompressing, as needed. If you select an operation with an extra number of actions, you will be prompted with the following error:

[Root@linux tmp]# tar-cuf Test.tar *.txt

Tar:you may isn't specify more than one '-acdtrux ' option

Try ' tar–help ' or ' tar–usage ' for the more information.

Common options:

-f,–file Use File file name, this is required, and is the last parameter, immediately after the file file name

-J,–BZIP2 call bzip2 compression or decompression, compressed package format for tar.gz or tgz

-z,–gzip call gzip compression or decompression, compressed package format for TAR.BZ2

-v,–verbose Displays the file information during the tar operation.

-p,–preserve-permissions Keep original file properties, not changed by user

Basic Usage Example: packing and unpack of tar:

# TAR-CF All.tar *.jpg

This command is to make all. jpg files into a package named All.tar. -C indicates the creation of a new package,-f Specifies the file name of the package.

# TAR-RF All.tar *.gif

This command adds all the. gif files to the All.tar package. -R means to add a file.

# Tar-uf All.tar logo.gif

This command updates the logo.gif file in the original tar package All.tar, and-U is the meaning of the update file.

# TAR-TF All.tar

This command lists all the files in the All.tar package----------T is the list of files

# TAR-XF All.tar

This command is to solve all the files in the All.tar package-----------tar.gz compression and decompression of the package:

# TAR-CZF all.tar.gz *.jpg

This command is to make all. jpg files into a tar package and use gzip compression to generate a gzip-compressed package named all.tar.gz

# TAR-XZF All.tar.gz

This command is to untie the packets generated above. TAR.BZ2 Compression and decompression:

# TAR-CJF all.tar.bz2 *.jpg

The command is to make all. jpg files into a tar package, and call bzip2 compression to generate a BZIP2 compressed package named all.tar.bz2

# TAR-XJF ALL.TAR.BZ2

This command is to untie the packets generated above.

4. zip

The ZIP program compresses the file to end with a. zip, and its corresponding decompression program is unzip.

Zip Common parameter Description:

-M: Move the compressed file to the compressed file

-R: Recursive compressed folder

-x: Exclude Files after parameters

-I: Include files after parameters

-1: The fastest compression, compression ratio is the worst

-9: Compress the slowest, compression ratio best compression: Zip all.zip files

[Root@linux tmp]# zip all.zip *.txt

Adding:test1.txt (stored 0%)

Adding:test2.txt (stored 0%)

Adding:test3.txt (stored 0%)

[Root@linux tmp]# ls

All.zip Test1.txt test2.txt Test3.txt

Zip is a packaged compression program that packs and compresses multiple files into a single file. While Gzip and bzip2 are only compression programs, multiple files will be compressed into multiple compressed files respectively.

Gzip Compress multiple Files:

[Root@linux tmp]# gzip *.txt

[Root@linux tmp]# ls

test1.txt.gz test2.txt.gz test3.txt.gz

Bzip2 Compress multiple files: [Root@linux tmp]# bzip2 *.txt

[Root@linux tmp]# ls

test1.txt.bz2 test2.txt.bz2 test3.txt.bz2 Decompression: Unzip All.zip

5. rar

RAR program compressed file with a. rar end, and its corresponding decompression program is Unrar. It should be noted that the process RAR files need to install RAR for Linux. Compression: RAR A All.rar files decompression: Unrar e All.rar

6. Summary

1. The concept of packaging and compression:

Packaging: Packs a large number of files or directories into a single file. (Multiple to one)

Compression: Compresses a large file into a small file. One-to-one

2. The original file will continue to exist regardless of package or unpack. and compression and decompression, the original file will disappear.

3. Both Zcat and Bzcat extract the contents of the compressed file to standard output, and the original file will remain.

4. BZIP2 does not support compressed folders, and the gzip-r parameter can support compressed folders.

5. zip is a packaged compression program, while Gzip and bzip2 are just compression programs.

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.