The decompression command __linux under Linux

Source: Internet
Author: User
Tags bz2 posix uncompress

There are many compression tools in Linux, this article mainly introduces Gzip/gunzip/zcat, Bzip2/bunzip2/bzcat, tar, Zip/unzip.

For ease of presentation. We first set up a text file called "Test.txt", which reads as follows:

Hello!
This is a test!
End of file.
1. Gzip/gunzip/zcat

Gzip is used to compress common files; Gunzip is used to extract the compressed files that are created by gzip; Gcat is used to view the compressed file source content that gzip builds.
Gzip can only be used to compress normal files, note that it is a normal file. The entire directory cannot be compressed into a single file, and if we compress the directory recursively, Gzip recursively enters each subdirectory and compresses the normal files in turn. Gzip-Created compressed files default to. gz,-gz, and. Z as extensions, depending on the file system type, table 1 shows the file system for different suffix names.

name extension File System
. gz Ext file system on Linux
-gz VFS (virtual file system)
. z MS-DOS (Microsoft Disk operating system), Windows NT fat, os/2 fat, Atari

The parameter options for gzip are as follows:

-C: The compressed data output will be screen (do not generate a compressed file).
-D: uncompress file-
f: Force overwrite existing file-
K: Keep source file (default is not retained)-
t: Test the integrity of the compressed file (used with the-v option)-
R: Recursive compression of all files-
V: Verbose output execution process (default does not output)
-1: Fastest compression with speed.
-9: The compression rate is best compressed. (Can change from 1-9, default is 6)

For example, to compress a previously created "test.txt" file, you can enter the following directive:

$ gzip-krv test.txt
test.txt:     0.0%--Replaced with test.txt.gz

Note that the GZIP compression tool by default is to replace the source file with a compressed file, if you want to retain the source file, you need to explicitly specify ' k ' parameters, the above-KRV represents the retention of source files, recursive compression of all files and detailed output compression process.
You can see from the output that there are three parameters: source file –test.txt, compression ratio –0.0% and output file –test.gz.

If we want to decompress the file we just created, just enter the following instructions

$ GZIP-DV test.txt
gzip:test.txt already exists; Do you wish to overwrite (Y or n)? y
test.txt.gz:      0%- -Replaced with Test.txt

As you can see from the output, there is a "test.txt" file in the current directory, so there is a hint of whether or not to overwrite if we don't want it to output the content. You can add the "-f" argument.

Gunzip is an uncompressed version of Gzip, which provides only the ability to decompress, with the same parameters as gzip (excluding the "-D" parameter), for example, we want to extract the test.txt.gz that we just created can be entered as follows:

$ gunzip-v test.txt.gz
test.txt.gz:      0.0%--Replaced with test.txt

Zcat is used to view the contents of the source file corresponding to the gzip compressed file. Use the following:

$ zcat test.txt.gz This is
a test!
2. Bizp2/bunzip2/bcat

BZIP2 has a better compression ratio than gzip, and its usage is almost the same as that of gzip. The compressed file created by Bzip2 is a. bz2 extension, and the following are common parameters for bzip2:

-C: The compressed data output will be screen (do not generate a compressed file).
-D: uncompress file-
f: Force overwrite existing file-
K: Keep source file (default is not retained)-
t: Test the integrity of the compressed file (used with the-v option)-
R: Recursive compression of all files-
V: Verbose output Execution (default does not output)-
Z: Compress files (default parameters)

BUNZIP2 is used to extract the compressed file created by bzip2, bcat to view the contents of the bzip2 compressed file corresponding to the source file. They are used similar to Gzip/gunzip/zcat, do not repeat here, please refer to the use of gzip/gunzip/zcat. 3. Tar

Most of the gzip and BIZP2 commands are compressed for a single file, although they can be recursively compressed, but are compressed based on a single file, which means that a compressed file is created for each file in the directory, instead of creating an entire archive, To use the tar command, it simply packs multiple catalogs (without compression) or compresses the packaged content through gzip and bzip2. The tar command has multiple parameters that support multiple operations. Now let's take a look at the use of the tar command.

The parameters of the tar command are grouped into categories, including master operations, manipulation adornments, rewrite controls, device chunking, selection of archive formats, device chunking, compression options and hint options, and more. This article refers to main operations, select Archive format, compression options, and hint options. These parameters are as follows:

/* Main operation option

/-A: Append the tar format archive to archive-
C: Create a new archive-
r: Append file to archive end-
T: List the contents of the Archive-
u: Update the files in the archive and add if they do not exist in the archive. -
x: Extracting files from archive

/* Select archive format option

/h: After document format, document format has the following several
   gnu--1.13.x (default format is also common)
   OLDGNU--GNU format as Per tar <=1.12
   pax--posix 1003.1-2001 (pax)
   posix--equivalent to pax ustar--
   POSIX 1003.1-1988 (ustar) format
   V7--old V7 tar Format/

* compression option

/A: Automatically determine the compression program based on the extension-j: Compressed by BIZP2-Z: Compressed by
gzip-
z: Compressed by compress

/* Other options */

V: Verbose output compression process-
f: Specify a compressed file name or file name to extract

Like me? To compress the above Test.txt file, you can enter the following command:

$ TAR-JCF test.txt.tar.bz2 test.txt

Or

$ TAR-ZCF test.txt.tar.gz test.txt

Or

$ TAR-ACF test.txt.tar.gz test.txt

The first and second of these are compressed using different compression tools, and the third is to automatically determine the compression tool based on the extension. If we're going to unpack, we'll just replace the "-C" argument with the "-X" argument.

Of course, we can also do without compression, just a number of files for a simple archive, you can enter the following:

$ TAR-CF [Output-file] [Input-file]

where Output-file and Input-file specify the output file name and the name of the file to be archived, respectively.

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.