Summary and use of compression tools under Linux (see Private dishes)

Source: Internet
Author: User

1 compression

gzip command

Options

-C Data Flow redirection, which can be positioned as a file

-R recursive compression, that is, deep sub-directory

-V displays redundant information such as name and compression ratio

-D Decompression

-# plus the number indicates the compression level, the higher the compression ratio, but the slower


① did a very simple experiment.

[Email protected] tmp]# ll-htotal 128k-rw-r--r--. 1 root root 128K June 03:00 Test[[email protected] tmp]# gzip-v-9 testtest:99.9%--Replaced with Test.gz[[email prot Ected] tmp]# ll-htotal 4.0k-rw-r--r--. 1 root root 166 June 03:00 Test.gz[[email protected] tmp]# gzip-d test.gz [[email protected] tmp]# gzip-v-1 test test : 99.6%--Replaced with test.gz

② How to keep the original file?

A solution I think is very useful, above the-C command

[[email protected] tmp]# gzip-c Test > Test.gz[[email protected] tmp]# lltotal 132-rw-r--r--. 1 root root 131072 June 03:00 Test-rw-r--r--. 1 root root 166 June 03:03 test.gz

④ use Zcat can read the compressed file directly, if the cat can read the original file, so called Zcat = =

[Email protected] tmp]# Zcat test1.sh.gz This is a test.



bzip2 command

It is said that there is a better compression ratio than zip, the command line is used, it is recommended to use similar sub-options

Did a simple little experiment.

[[email protected] tmp]# gzip-9-v-c test >test.gztest:99.9%[[email protected] tmp]# bzip2-9-v-c test >test.bz 2 test:2978.909:1, 0.003 bits/byte, 99.97% saved, 131072 in,.


Sure enough, other uses similar, not recommended to continue to try

Bzcat is the same.

[Email protected] tmp]# Bzcat test1.sh.bz2 This is a test.


Let's see how to package and compress the unpacked package.

Tar command

There's a section on the Internet that's good, take it off here

Parameters:
- C: Create a compressed file parameter directive (the meaning of Create);
-x: Unlock the parameter instructions for a compressed file!
-T: View the files inside the Tarfile!
in particular, in the release of the parameters, c/x/t can only exist one! Cannot exist at the same time! Because it is not possible to compress and decompress simultaneously.
-Z: Do you have the properties of gzip at the same time? i.e. do I need gzip compression?
-j: Do you have bzip2 properties at the same time? i.e. is it necessary to compress with bzip2?
-V: Files are displayed during compression! This is commonly used, but is not recommended for use in the background execution process!
- F: Use the file name, please note, after F to immediately answer the file name Oh! Don't add any more arguments!
For example, the use of "TAR-ZCVFP tfile sfile" is the wrong way of writing, to write "TAR-ZCVPF tfile sfile" to Oh!
- P: Use original file properties (attributes are not changed according to user)
- P: You can use absolute path to compress! This is convenient for configuration files, general backup/etc Best Use-P

-N: Newer than next date (YYYY/MM/DD) will be packaged in the new file!
--exclude file: In the process of compression, do not package file!

-C directory Specifies the extracted directory

Basically the usual ones have been explained

Note the following points


1 Tar practical time to consider, of course, is compressed, then consider the use of zip or bzip,zip using Z,bzip J, unzip the same

2-f is followed by the file, so F is immediately followed by the compressed file to be created, and then the source file to be compressed


Let's keep doing our little experiment.

① package tmp with all except test files to the/root/backup/directory, using BZIP2 compression

[Email protected] tmp]# tar-jcvf/root/backup/tmp.bz2/tmp--exclude testtar:removing leading '/' from member Names/tm p//tmp/test.bz2/tmp/test.gz/tmp/test1.sh.bz2

② at this time required to retain the file attributes, the/ETC/MY.CNF compressed into/root/backup/directory, the name asked My.bak

[Email protected] tmp]# tar-jcvpf/root/backup/my.bak/etc/my.cnftar:removing leading '/' from member NAMES/ETC/MY.CNF

③ in the root home directory, the file is later than July 11, 2015 backup, named 2015.7.11.bak

[Email protected] ~]# tar-jcvp-f/root/backup/2015.7.11.bak/root-n 20150711

④ Add a file/tmp/test in the ③ compressed file and view

[Email protected] ~]# tar-rf/root/backup/2015.7.11.bak.tar/tmp/testtar:cannot Update compressed Archivestar:error Is isn't recoverable:exiting now

Added a half day, found this error, just realize that I have been compressed to this, so the best way is to re-compress, of course, for a tar package to add re-compression can also

[Email protected] ~]# tar-jcvpf/root/backup/2015.7.11.bak/tmp/test/root-n 20150711[[email protected] ~]# TAR-TVF /root/backup/2015.7.11.bak

Or so

[Email protected] ~]# tar-cf/root/backup/2015.7.11.bak/root[[email protected] ~]# Tar-rvf/root/backup/2015.7.11.bak /tmp/test tar:removing leading '/' from member Names/tmp/test[[email protected] ~]# Tar-tvf/root/backup/2015.7.11.bak ...-rw-r--r--root/root 131072 2015-06-27 04:27 tmp/test


In short, the other is to use it later, of course, the front can also not apply-, such as the tar XF, this is another style, Big day I also forgot

This article is from the "Learning Path of Kai Learning" blog, please make sure to keep this source http://qixue.blog.51cto.com/7213178/1673917

Summary and use of compression tools under Linux (see Private dishes)

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.