Linux compression and packaging

Source: Internet
Author: User

Linux compression and packaging

Compression Technology is generally divided into two types: lossy compression and lossless compression. In linux, data loss is generally not allowed, so they are all lossless compression.

In linux, compression technology can be divided into two types:

Gzipbzip2

Gzip

Gzip is a compression technology that comes before bzip2. The general usage is as follows:

Gzip file

File is the file to be compressed. The generated compressed file usually replaces the original file. The compressed file has the same time attribute and permissions as the original file.

If you want to retain the original file, you can use the c option and redirection implementation.

Gzip-cv file> file.gz

C is to locate the output to the standard output, and v is to display the details of the compression process.

The decompressing command corresponding to gzip: (currently, gzip can uncompress files compressed by compress, zip, gzip, and other software)

Gzip-d file.gz (or use the gunzip command)

You can use zcat (refer to cat) to directly view the content of a compressed plain text file.


Bzip2

Bzip2 is an improvement of gzip technology. It generally has a good compression ratio, but the speed is relatively slow. Bzip2 is used in a similar way as gzip.

Differences:

The decompress command corresponding to bunzip2 is bunzip2 (bzip2-d is generally used for decompressing)
Use bzcatto retrieve the content of the .bz2 file.


Disadvantage: These compression commands can only compress and decompress a single file. Although gzip and bzip2 can also compress directories, these two commands compress directories by compressing all the files in the directories! Therefore, it is necessary to package files.

Tar
Packaging is the process of bundling many files into a large file. The tar command is used to package the file. The tar command is generally used as follows:

Package file: tar-cv-f filename.tar filename1 filename2 (c option indicates creating a package file, f specifies the file name generated after packaging, v displays the package file information)

Unpackage file: tar-xv-f filename.tar (x indicates the unpackage file, f specifies the package file name)

View the file contained in the package: tar-t-f filename.tar (-t displays the file name in the package)

Tar has the following two features:

The permission to recover a file from a packaged file is the permission of the user who executes the recovery operation. Unless you are a root user, the permission is the permission of the original user. The tar command is used to process the path name of an archive object. By default, the path name is relative, not absolute. When creating an archive file, the tar command will simply delete the slash at the beginning of the path name.
It can be seen that when the absolute path is used for packaging files ,~ /Playground will be expanded to/home environment? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> keys/wrzPwrXEzsS8/keys 74cm + s/1ob21lwre + tseww + a1xLj6wre + keys/keys + keys/KGjCgo8cD48L3A + Cgp0YXLD/examples/Who3RhciDD/examples + oaPNqLn9IGZpbmQgw/examples + w/examples + samples + o6zA/cjno7oKPHA + Signature = "file-a'-exec tar rf playground.tar '{} ''+ '// r is the append option.

File name conventions in linux:

*. Z files compressed by the compress program;
*. Files compressed by the gz gzip program;
*. Bz2 bzip2 files compressed by the program;
* The data packaged by the. tar program has not been compressed;
* .Tar.gz tar package files, which are compressed by gzip
* .Tar.bz2 tar package, which is compressed by bzip2

In addition, if the files packaged by tar are compressed, the names of the obtained files are different.

Tarfile: package file tar-cv-f file.tar tarball: Package and compress the file tar-jcv-f file.tar.bz2

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.