Linux file compression and packaging

Source: Internet
Author: User
Tags bz2 gz file

1. Compression and packaging

Compression: Use a more space-saving record to record file data and reduce the amount of file usage. Advantage: The same capacity can store more data, and the amount of data at the time of transmission decreases, thus faster.

Packaging: Packaging multiple files into a large file, the actual file consumption of the capacity did not decline. Pros: Let the collection of files have a uniform name.

2.Linux Common zip file extension

*.GZ gzip Compressed files

*.BZ2 bzip2 Compressed Files

*.tar Tar program packaged files

*.tar.gz Tar program packaging, gzip compressed files

*.TAR.BZ2 tar program packaging, bzip2 compressed files

3.GIZP compression command

Use the broadest compression command to unlock compress,zip,gzip compressed files

gzip [-cdtv#] [file name]

-C: Output compressed data to the screen, with data flow redirection to handle

-D: Decompression parameters

-T: Used to verify the consistency of the compressed file and see if the file has errors

-V: Output file compression ratio and other information

-#: Compression level 0-9,1-9 compression ratio increase slower, default is 6

gzip -9 -v-c test.txt>test.gztest.txt:     38.0%[email protected]: ls test.gz  test.txt[email protected]:gzip -D test.gz[email protected]:ls Test  Test.txt

Zcat to view a text file after gzip compression

4.BZIP2 compression command

Compression commands that are better than gzip compression

bzip2 [-cdkzv#] File name

-C: Output data generated during compression to the screen

-D: decompressed parameters

-K: Keep the original file

-Z: Compressed parameters

-V: can show the compression ratio of the original file/compressed file

-#: With gzip

bzip2 -kvz test.txt  test.txt:  1.366:1,  5.858 bits/  byte26.78534in391  out.[ Email protected]:lstest.txt  test.txt.bz2

5.tar Packaging commands

Multiple files packaged into one large file for ease of compression (if not packaged, compression is compressed for each file separately, and then to the overall compression after packaging)

tar [-j|z] [-CV] [-f new filename] filename//packaging and compression

tar [-j|z] [-TV] [-f new filename] FileName//view file name

tar [-j|z] [-XV] [-f new FileName] [-C directory]//Unzip

Parameters:

-C: New package file

-T: View the contents of the packaged file with those file names

-X: Unpacking or decompressing

The above 3 does not appear in the same sequence of commands

-J: Compression/decompression via BZIP2 support

-Z: Compression/decompression via GZIP support

-V: The file name being processed is displayed during compression/decompression

-F: The file name to be processed later

-C: Specific directory decompression

-P: Retain the original permissions and properties of the backed up data

Simple Record

Gzip compression: TAR-ZCVF filename.tar.gz file directory or name to compress

Gzip Decompression: TAR-ZXVF filename.tar.gz-c unzipped Directory

Gzip View: TAR-ZCVF filename.tar.gz

bzip2 compression: TAR-JCVF filename.tar.bz2 file directory or name to compress

BZIP2 Decompression: TAR-JXVF filename.tar.bz2-c unzip the directory

BZIP2 View: TAR-JCVF filename.tar.bz2

Unlock a file

TAR-JTVF [Package file] |grep ' part filename '//view

TAR-JXVF [Package file] [filename to be unpacked]

[Email protected]:~$Tar-jcvf/home/lht/test2/test.Tar. bz2 testtest/Test/world.txttest/test111.txttest/test333.txttest/444. Txttest/hello.txttest/test.txttest/. Hello.swptest/Test222.txt[email protected]:~/test2$Tar-JTVF test.Tar. bz2 |grep 'test/test'//View-rw-r--r--xxx/xxx0 2018- on- +  A: -test/Test111.txt-rw-r--r--xxx/xxx0 2018- on- +  A: -test/Test333.txt-rw-r--r--xxx/xxx534 2018- on- +  +: Wutest/Test.txt-rw-r--r--xxx/xxx0 2018- on- +  A: -test/Test222.txt[email protected]:~/test2$Tar-JXVF test.Tar. bz2 test/Test111.txt//Solving a single file test/Test111.txt[email protected]:~/test2$lstest test.Tar. Bz2[email protected]:~/test2$lsTesttest111.txt

Package a directory, not contain some files

TAR-JCVF [Package file name]--exclude= unwanted files [files that need to be packaged]

tar -jcvf test2. tar. bz2--exclude=test/test*/home/xxx/testtar: Remove the Beginning "/"from the member name/home/xxx/test// home/xxx/test/world.txt/home/xxx/test/444.txt/home/xxx/test/hello.txt/Home /XXX/TEST/.HELLO.SWP//package only files that do not contain test/test

Back up only new files

TAR-JCVF [package filename]--newer-mtime= ' time ' [file to be packaged]

The above command can only package files that have changed after a certain time

Linux file compression and packaging

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.