A summary of the various types of compression formats on Linux

Source: Internet
Author: User
Tags gz file rar

I am using an environment that is 64-bit Red Hat Enterprise Linux Server release 6.4 (Santiago)

1.compress and *. Z File

The role of the Compress program is: Compress reduces the size of the named files using adaptive Lempel-ziv coding

That is: compressing the file using adaptive Lempel-ziv encoding

If you do not have compress installed, you will be prompted with an error after entering the Compress command:

-bash:compress:command not found

Run the following command to install:

Yum Install ncompress

(arch:x86_64;version:4.2.4-54.el6_2.1)

Compress the file test to test. Z

Compress test

After running the command, the test file disappears and a new file test appears. Z. To unzip the file, enter one of the two commands below.

compress-d test. Zuncompress test. Z

The Compress command cannot compress the entire directory, only compresses all files in one directory for recursive compression and decompression

Compress-r Testdiruncompress-r TestDir

2.gzip and *.gz files

The description of gzip in man is: gzip reduces the size of the named files using Lempel-ziv coding (LZ77)

That is, the file is compressed using the Lempel-zip encoding (LZ77)

To compress the file test to Test.7gz, enter the following command

Gzip Test

View the contents of the compressed file, can be directly viewed with zcat, such as:

echo "ABCD" > Wordgzip wordzcat Word

You can see the output "ABCD"

Gunzip is used to decompress the GZ file and extract the previous test.gz, you can use the following command:

Gunzip test.gz

Recursive compression and decompression of files in the directory requires the addition of a parameter-R

Gzip-r Testgunzip-r test.gz

3.bzip2 and *.bz2 files

The description of bzip2 in man is: bzip2 compresses files using the Burrows-wheeler block sorting text compression algorithm, and Huffman codi Ng

Compress files even with Burrows-wheeler block sort text compression algorithm and Huffman encoding

command to compress files by bzip2 (select one)

BZIP2 testbzip2-z Test

Commands for extracting files by bzip2 (select one)

BUNZIP2 test.bz2bzip2-d test.bz2

To view the compressed file, use the command bzcat, similar to Zcat, that is, "Bzcat file name"

4.tar and *.tar, *.tar.gz, *tar.bz2, *.tar.xz files

The tar command can be used to compress a directory, such as a directory testdir, to compress it to Testdir.tar

TAR-CVF Testdir.tar TestDir

-C: Create a compressed archive

-V: Files are displayed during compression

-F: Use the file name (f must be used as the last parameter, followed directly with *.tar)

After compression, the original test does not disappear. If you want to unzip the Testdir.tar, enter the command:

TAR-XVF Testdir.tar

Depending on the parameters of the tar command, you can compress the directory testdir into tar.gz format, tar.bz2 format, and TAR.XZ format, respectively

1) compression and decompression of tar.gz format (-Z Filter the achive through gzip)

TAR-ZCVF testdir.tar.gz TESTDIRTAR-ZXVF testdir.tar.gz

2) compression and decompression of tar.bz2 format (-J filter the archive through bzip2)

TAR-JCVF testdir.tar.bz2 TESTDIRTAR-JXVF testdir.tar.bz2

3) TAR.XZ format compression and decompression (-J filter the archive through XZ)

TAR-JCVF testdir.tar.xz TESTDIRTAR-JXVF Testdir.tar.xz

5.zip and *.zip files

To compress the directory TestDir into the file Testdir.zip, use the following command:

Zip-r Testdir.zip TestDir

To view the contents of the extracted zip file:

Unzip-v Testdir.zip

Extract the Testdir.zip to the current directory (two commands below to select a run)

Unzip-o Testdir.zipunzip-o-D. Testdir.zip

-O means overwrite the file if it has a duplicate name: Overwrite existing files without prompting (dangerous option)

-D is the compressed directory: an optional directory to which to extract files

Now assume that there is a file word. To add a file to Testdir.zip Word, you can use the command: (the original word disappears after you finish running)

Zip-m Testdir.zip Word

To delete a file from Testdir.zip Word, you can use the command: (Word is deleted and it does not exist)

zip-d Testdir.zip Word

6.rar and *.rar

RAR programs need to be manually installed before they can be used

I downloaded one from this address: http://www.rarlab.com/download.htm

Download is: RAR 5.20 beta 4 for Linux x64

The downloaded file name is: rarlinux-x64-5.2.b4.tar.gz; size 1.08MB

After saving to your Linux system, unzip the file

Tar rarlinux-x64-5.2.b4.tar.gz

You can see the folder RAR, enter the command after entering

Make-f Makefile

You can see that makefile calls the following commands

Mkdir-p/usr/local/binmkdir-p/usr/local/libcp rar unrar/usr/local/bincp RARFILES.LST/ETCCP default.sfx/usr/local/ Lib

Installation is complete! This time directly input RAR can see the various parameters and meaning of rar

To compress TestDir to Testdir.rar, use the command:

RAR a Testdir.rar TestDir

Unzip the Testdir.rar to the current directory, using the command (select one):

rar x Testdir.rarunrar e Testdir.rar

7.7za and *.7z files

7za also requires manual installation after download

: HTTP://SOURCEFORGE.NET/PROJECTS/P7ZIP/FILES/P7ZIP/9.20.1/

Download file: p7zip_9.20.1_x86_linux_bin.tar.bz2

After downloading to the local Linux system, unzip:

Tar xjf p7zip_9.20.1_x86_linux_bin.tar.bz2

The directory p7zip_9.20.1 can be seen after decompression. Call the install.sh script inside with root permission

Installation is complete! This time directly into the 7za or command "man 7za" can see the various parameters and the meaning of 7za

Compress directory TestDir to testdir.7z:

7za a-t7z testdir.7z TestDir

The meaning of each part

1) A Add File

2)-T compression type selected here 7z (this is also the default value)

3) testdir.7z the file name after compression

4) TestDir Compressed files (can be one or more files, directories)

Unzip the contents of testdir.7z to the current folder:

7za x testdir.7z-r-o./

1)-R recursively unzip all subfolders

2)-O extract to the specified directory (followed by direct path, no space)

8. A script for extracting files

If you feel that the various compression files in Linux are not as cumbersome as they are, the following fool script should help:

Script: extract.sh

#!/bin/shif [  "$#"  -ne 1 ]; then    echo  "Input parameters: extracted files"     exit 0fiif [ -f  "$"  ]; then    case   "$"  in        *.tar )  tar xf $1 ;;         *.tar.bz2 | *.tbz2 )  tar xjf $1  ;;         *.tar.gz | *.tgz )  tar xzf $1  ;;         *.bz2 )  bunzip2 $1 ;;         *.gz )  gunzip $1 ;;         *.zip )  unzip $1 ;;         *.rar )  unrar e $1 ;;         *. z )  uncompress $1 ;;         *.7z )  7z x $1 ;;         * )  echo  type not recognized  ;;         esacelse    echo  "$": file does not exist or has no permissions fiexit  0

END

A summary of the various types of compression formats on Linux

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.