8.2 Compression, decompression, and archiving tools

Source: Internet
Author: User
Tags gz file uncompress

Compress/uncompress

File-roller for use on graphical interfaces

-D: Uncompressed, equivalent to uncompress
-C: Result output to standard output, do not delete original file
-V: Show details

Compress:compress back with file
Suffix Band. Z
Compress compress files and delete files

compress-d m.z-d Decompression-d=uncompress

-C (Option-C results output to standard output, display to screen but do not delete source files) can be redirected
Compress-c m >m.z compress the file and redirect to M. In Z

Zcat uncompressed display on the screen, do not want to display it in the file, but keep the original compressed file
Zcat m.z > M.M zcat extract m.z to M.M file

Gzip/gunzip

Common options:
-D: Decompression, equivalent to GUNZIP-C: outputs the compressed or decompressed results to the standard output
-#: 1-9, specify the compression ratio, the larger the value, the greater the compression ratio

Feature: The original file is not preserved after compression is complete. Compression rate is greater than compress.
Example:
Gzip m compression
gzip-d m decompression
Gzip-9 m Specify compression ratio

The same file with gzip compression is better than compress compression effect
Gzip-d and Gunzip are all decompressed

Gunzip m.gz

Gzip-c the compressed or decompressed results to the standard output display to the screen, or you can use the redirect
Gzip-c m > m.gz compress m file and redirect to m.gz file


Zcat also applies to compressed files with the. gz suffix.

Bzip2/bunzip2/bzcat

End of bzip2 compressed with. bz2
Bzip2-b Compress and retain the original file

BZIP2 is better than gzip and compress compression,-#: 1-9, compression ratio, default is 9.

bzip2-d = = = Bunzip2

Bzcat can be redirected to a file as well as the above zcat effect

Xz/unxz/xzcat

Common options:
-k:keep, keep original file-D: Unzip-#: 1-9, compression ratio, default = 6
Xzcat: View text file contents without explicit decompression

Features: Use the-k option to preserve the original file after compression is complete. Compression ratio: xz>bzip2>gzip>compress

Zip/unzip

Packaging compression
zip–r/testdir/sysconfig/etc/sysconfig/

Features: You can compress packages for folders. The compression rate is not very high.
Unpacking and decompression
Nzip Sysconfig.zip
Cat/var/log/messages | Zip messages-
UNZIP-P Message > Message

Tar

Tar can create archives for files and directories. With tar, users can create files (backup files) for a specific file, or they can change files in the file or add new files to the file. Users can create files on any device, such as a floppy disk. With the tar command, you can package a whole bunch of files and directories into a single file, which is useful for backing up files or combining several files into one file for easy network transmission. The tar on Linux is the GNU version.

Syntax: tar [main option + Secondary options] file or directory

When using this command, the main option is required, and it tells Tar what to do, auxiliary options are auxiliary and can be used.
Main options:
C Create a new profile. Select this option if the user wants to back up a directory or some files.
R appends the file to be archived to the end of the archive file. For example, you can use this option to append a forgotten directory or file to a backup file if you have already made a backup file and you find that there is a directory or some files that you forgot to back up.
T list the contents of the archive file and see which files have been backed up.
U update file. That is, replace the original backup file with the new file, if the file you want to update is not found in the backup file, append it to the end of the backup file.
X release the file from the archive file.

Accessibility Options:

b This option is set for the tape drive. It is followed by a number that indicates the size of the chunk and the system preset value is (20*512 bytes).
F using a file or device, this option is usually required.
K Save the file that already exists. For example, we restore a file, during the restore process, encountered the same file, will not be overwritten.
m when restoring files, set the modification time of all files to now.
M Create a multi-volume archive file for storage on several disks.
V Detailed report of file information processed by tar. Without this option, TAR does not report file information.
W each step requires confirmation.
Use gzip to compress/unzip the file, plus this option to compress the archive file, but be sure to unzip it using this option when restoring.

Before summing up the various types of compressed files, the first two concepts should be clarified: packaging and compression. Packaging refers to a lot of files or directories into a total file, compression is a large file through some compression algorithm into a small file. Why should we differentiate between these two concepts? In fact, this is because many of the compression programs in Linux can only be compressed for a single file, so when you want to compress a lot of files, you have to use a different tool to first make the whole heap of files into a package, and then the original compression program compression.

There are many options for the tar command (which can be viewed with man tar), but there are a few options that are commonly used, as illustrated below:
TAR-CF all.tar . jpg
This command is to make all. jpg files into a package named All.tar. -C is the file name that represents the generation of a new package,-f specifies the package.
TAR-RF all.tar
. gif
This command adds all the. gif files to the All.tar package. -R is meant to increase the file.
??????? Tar-uf all.tar logo.gif
This command is to update the original tar package All.tar in the logo.gif file,-U is to indicate the meaning of the update file.

TAR-TF All.tar
This command is to list all the files in the All.tar package,-T is to list the meaning of the file
TAR-XF All.tar
This command is to solve all the files in the All.tar package,-X is the meaning of unpacking
These are the most basic uses of tar. Tar provides a special feature to facilitate the user's ability to compress or decompress a file while unpacking the package. This is what tar can call other compression programs while packaging or unpacking, such as calling Gzip, bzip2, and so on.

1) Tar call gzip

Gzip is a compression program developed by the GNU organization, and the. Gz end file is the result of gzip compression. The decompression procedure relative to Gzip is gunzip. Use the-Z parameter in tar to invoke gzip. Here's an example:

    tar -czf all.tar.gz *.jpg

This command is to make all. jpg files into a tar package and compress them in gzip to generate a gzip compressed package named all.tar.gz
Tar-xzf all.tar.gz
This command unlocks the package generated above.

2) Tar call bzip2

Bzip2 is a more compressible compression program, and the. bz2 end of the file is the result of bzip2 compression. The decompression procedure relative to bzip2 is bunzip2. Use the-j parameter in tar to invoke bzip2. Here's an example:
TAR-CJF all.tar.bz2 *.jpg
This command is to make all. jpg files into a tar package, and call bzip2 compression to generate a BZIP2 compressed package named all.tar.bz2
TAR-XJF all.tar.bz2
This command unlocks the package generated above.

??? 3) Tar call compress

Compress is also a compression program, but it seems that people who use compress are not as good as gzip and bzip2. The file at the end of Z is the result of bzip2 compression. The decompression procedure relative to compress is uncompress. Use the-Z parameter in tar to invoke gzip. Here's an example:
TAR-CZF All.tar.z *.jpg
This command is to make all. jpg files into a tar package, and call compress compression to generate a uncompress compressed package named All.tar.z
Tar-xzf All.tar.z
This command unlocks the package that was created above.

With the above knowledge, you should be able to solve a variety of compressed files, the following for the TAR series of compressed files to make a summary:
1) for files ending in. tar
TAR-XF All.tar
2) for files ending in. gz
Gzip-d all.gz
Gunzip all.gz
3) for files ending with. tgz or. tar.gz
Tar-xzf all.tar.gz
Tar-xzf all.tgz
4) files ending with. bz2
Bzip2-d all.bz2
BUNZIP2 all.bz2
5) For tar.bz2 end of file
TAR-XJF all.tar.bz2
6) for. Z End of File
Uncompress all. Z
7) files ending with. tar.z
Tar-xzf All.tar.z

1) for. zip
Linux provides a zip and unzip program, ZIP is a compression program, unzip is the decompression program. They have a lot of parameter options, here are just a brief introduction, still examples of its use:
Zip All.zip *.jpg
This command compresses all. jpg files into a zip package

????? Note: If you are compressing a folder, add the-r parameter, which means that recursive compression is called, such as:

????? Zip-r Temp.zip Temp

??? ??? Unzip All.zip
This command is to extract all the files in the All.zip.

SPList:: Splitting a file into multiple files

Split a large tar file into multiple small files
Split–b size–d Tar-file-name Prefix-name
Split-b 1m–d mybackup.tgz Mybackup-parts
Split-b 1M mybackup.tgz Mybackup-parts
Merge:
Cat mybackup-parts* > mybackup.tar.gz

Cpio

Cpio function: Reply file from or to archive

The Cpio command is a file that is packaged and backed up by a redirect, a tool that restores replies, and files that end in. cpio or. Tar
Option-0: A copy of the file is packaged to generate a file or output to a device or redirected

-I: Unpacking

-T: Preview, view the contents of the file or output to the device

-V: Displays the file name of the packaging process

-D: Unpack the build directory and automatically create the directory when Cpio restore

-C: A newer storage method

find/etc/sysconfig/|cpio-ov >sysconfig.cpio Find files in/etc/sysconfig/directory package output to Sysconfig.cpio file with. Cpio End

Preview Sysconfig.cpio's content Cpio-tv < Sysconfig.cpio


Cpio-idv < Sysconfig.cpio unpacking is Sysconfig.cpio and generating the directory according to the absolute path

8.2 Compression, decompression, and archiving tools

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.