Compression and decompression of tar bz gz and other compressed packages in Linux

Source: Internet
Author: User
Tags gz file

In Linux, users often need to back up data in computer systems. To save storage space, backup files are often compressed. This article provides a general summary of the compression and decompression commands.

.Tar.gz
Decompress: Tar zxvf filename.tar.gz
Compression: Tar zcvf filename.tar.gz dirname

 

Decompression of * .tar.gz in Solaris may be different. Follow these two steps:

1. gzip-D * .tar.gz

2. Tar xvf *. Tar

Step 1: Decompress * .tar.gz to *. Tar.

Step 2: Decompress the *. tar file to decompress it.

---------------------------------------------
. Tar
Unpack: Tar xvf filename.tar

Tar xvf filename.tar-C dirname (decompress it to the specified folder dirname)
Package: Tar CVF filename.tar dirname
---------------------------------------------
. GZ
Decompress 1: gunzip filename.gz
Decompress 2: gzip-D filename.gz
Compression: gzip filename
.Tar.gz and. tgz
Decompress: Tar zxvf filename.tar.gz
Compression: Tar zcvf filename.tar.gz filename
---------------------------------------------
. Bz2
Decompress 1: Bzip2-D filename.bz2
Decompress 2: bunzip2 filename.bz2
Compression: Bzip2-Z filename
.Tar.bz2
Decompress: Tar jxvf filename.tar.bz2
Compression: Tar jcvf filename.tar.bz2 filename
---------------------------------------------
. Bz
Extract 1: Bzip2-D filename. bz
Decompress 2: bunzip2 filename. bz
Compression: Unknown
. Tar. bz
Decompress: Tar jxvf filename.tar. bz
Compression: Tar jcvf filename.tar. BZ filename
---------------------------------------------
. Z
Decompress: uncompress filename. Z
Compression: compress filename
. Tar. Z
Decompress: Tar zxvf filename.tar. Z
Compression: Tar zcvf filename.tar. Z dirname
---------------------------------------------
. Zip
Decompress: unzip filename.zip
Compression: Zip filename.zip dirname
---------------------------------------------
. Rar
Decompress: RAR x filename.rar
Compression: rar a filename.rar dirname

RAR Please download to: http://www.rarsoft.com/download.htm!
After decompression, copy rar_static to the/usr/bin directory (Other Directories specified by the $ PATH environment variable can also be used ):
[Root @ www2 TMP] # cp rar_static/usr/bin/RAR
---------------------------------------------
. LHA
Decompress: LHA-e filename. LHA
Compression: LHA-a filename. LHA filename

Lha please: http://www.infor.kanazawa-it.ac.jp /~ Ishii/lhaunix/download!
> After decompression, copy LHA to the/usr/bin directory (Other Directories specified by the $ PATH environment variable can also be used ):
[Root @ www2 TMP] # cp LHA/usr/bin/
---------------------------------------------
. Rpm
Unpack: rpm2cpio filename. RPM | cpio-Div
---------------------------------------------
. Deb
Unpack: Ar P filename. Deb data.tar.gz | tar zxf-
---------------------------------------------
. Tar. tgz .tar.gz. Tar. Z. Tar. BZ .tar.bz2. Zip. cpio. rpm

. Deb. SLP. ARJ. rar. Ace. LHA. lzh. LZX. LZs. Arc. SDA. SFX. lnx

. Zoo. Cab. kar. CPT. Pit. Sit. Sea
Decompress: Sex x filename .*
Compression: Sex a filename. * filename

Sex only calls related programs and does not support compression or decompression. Please note!
For sex, go to http://sourceforge.net/projects/sexto download it!
After decompression, copy sex to the/usr/bin directory (Other Directories specified by the $ PATH environment variable can also be used ):
[Root @ www2 TMP] # cp sex/usr/bin/

References:Linux File compression Tool Guide
In fact, help is the best method. Generally, you can use the "-- Help" parameter or man command (such as man TAR) for each command to get a common usage method!

---------------------------------------------

Tar command

Tar can create files and directories. Using tar, you can create a file (backup file) for a specific file, change the file in the file, or add a new file to the file. Tar was originally used to create files on tape. Now you can create files, such as floppy disks, on any device. Using the tar command, you can package a large number of files and directories into one file, which is very useful for backing up files or combining several files into one file for network transmission. Tar on Linux is of the GNU version.

Syntax: Tar [primary option + secondary option] file or directory

When you use this command, the main option is required, and it tells tar what to do. The auxiliary option is used for assistance and can be used.

Main options:

C. Create a new archive file. Select this option if you want to back up a directory or some files.

R: append the file to the end of the file. For example, if you have prepared a backup file and find that there is another directory or file that needs to be backed up and appended, you can use this option.

T list the file content and check which files have been backed up.

U updates the file. That is to say, replace the original backup file with the new file. If the file to be updated cannot be found in the backup file, append it to the end of the backup file.

X release a file from the file.

Auxiliary options:

B. This option is set for the tape drive. It is followed by a number to describe the block size. The default value is 20 (20*512 bytes ).

F. This option is usually required when you use an archive file or device.

K. Save the existing files. For example, if we restore a file, the same file will not be overwritten during restoration.

M sets the modification time of all files to the present when restoring files.

M creates a multi-volume archive file to store it on several disks.

V detailed report on the file information processed by tar. If this option is not available, tar does not report file information.

W each step requires confirmation.

Z uses gzip to compress/decompress the file. With this option, the file can be compressed. However, you must use this option to decompress the file during restoration.

Example 1: create a full-part sub-directory file named usr.tar in the/home directory.

$ Tar CVF usr.tar/home

Example 2: complete the sub-directories in the/home directory and compress them with the name usr.tar.gz.

$ Tar czvf usr.tar.gz/home

Example 3: Restore and decompress the backup file usr.tar.gz.

$ Tar xzvf usr.tar.gz

Example 4: The contents of the usr.tar backup file are displayed on the display in split screen mode.

$ Tar tvf usr.tar | more

To back up a file to a specific device, you only need to use the device name as the backup file name.

Example 5: You can create a backup file in a floppy disk of the/dev/fd0 device and copy all the files in the/home directory to the backup file.

$ Tar CF/dev/fd0/home

To restore files on a device disk, use the xf option:

$ Tar xf/dev/fd0

If the size of the backup file exceeds the storage space available for the device, such as a floppy disk, you can create a multi-volume tar backup file. The m option indicates that the tar command prompts you to use a new storage device. When you use the M option to archive a disk drive, when a floppy disk is full, the tar command reminds you to add a new floppy disk. In this way, you can save the tar file to several disks.

$ Tar CMF/dev/fd0/home

To restore the files on several disks, you only need to put the first disk into the soft drive, and then enter the tar command with the X and m options. If necessary, you will be reminded to add another floppy disk.

$ Tar xmf/dev/fd0

---------------------------------------------

Gzip command

There are two obvious advantages to reduce the file size. One is to reduce the storage space, and the other is to reduce the transmission time when the file is transmitted over the network. Gzip is a frequently used command in Linux to compress and decompress files, which is convenient and easy to use.

Syntax: gzip [Option] compressed (decompressed) file name

Meaning of each option:

-C writes the output to the standard output and keeps the original file.

-D. decompress the compressed file.

-L the following fields are displayed for each compressed file:

Compressed)

Uncompressed File Size)

Compression Ratio (ratio)

Uncompressed_name)

-R recursively searches for the specified directory and compresses all the files or decompress the files.

-T test to check whether the compressed file is complete.

-V displays the file name and compression ratio for each compressed and decompressed file.

-Num: Use the specified numeric num to adjust the compression speed.-1 (-- fast) indicates the fastest compression method (low compression ratio) and-9 (-- best) indicates the slowest compression method (high compression ratio ). The default value is 6.

Assume that a directory/home has a file named 123 aaa abc.

Example 1: compress each file in the/homecatalog into A. GZ file.

$ CD/home

$ Gzip *

$ Ls

123. GZ aaa.gz abc.gz

Example 2: extract each compressed file in Example 1 and list the detailed information.

$ Gzip-DV *

123. GZ:-50.0% -- replaced with 123
Aaa.gz:-50.0% -- replaced with AAA
Abc.gz:-50.0% -- replaced with ABC

$ Ls

123 AAA ABC

Example 3: detailed information of each compressed file in Example 1 is displayed without decompression.

$ Gzip-L *

Compressed uncompressed ratio uncompressed_name
28 4-50.0% 123
28 4-50.0% aaa
28 4-50.0% ABC
84 12-416.7% (totals)

$ Ls

123. GZ aaa.gz abc.gz

Example 4: compress a Tartar file, for example, usr.tar. the extension name of the compressed file is .tar.gz.

$ Gzip usr.tar

$ Ls

Usr.tar.gz

---------------------------------------------

Unzip command

How can I expand files compressed by WinZip in Microsoft Windows in Linux? You can use the unzipcommand to unexpand a compressed file named. Zip.

Syntax: unzip [Option] compressed file name. Zip

The meanings of each option are as follows:

-X file list: Decompress the file, but does not include the specified file.

-V.

-T whether the test file is damaged, but the pressure is not solved.

-D directory: Decompress the compressed file to the specified directory.

-Z only displays the annotation of the compressed file.

-N does not overwrite existing files.

-O overwrites existing files and does not require user confirmation.

-J. Do not recreate the directory structure of the document and decompress all the files to the same directory.

Example 1: extract text.zip from the current directory.

$ Unzip text.zip

Example 2: Decompress the compressed file text.zip under the specified directory/tmp. If the same file already exists, the unzip command must not overwrite the original file.

$ Unzip-N text.zip-D/tmp

Example 3: view the directory of the compressed file.

$ Unzip-V text.zip

---------------------------------------------

Zgrep command

The function of this command is to find a matching regular expression in a compressed file. The usage is the same as that of the grep command, except that the object operated is a compressed file. You can use the zgrep command to check whether a certain sentence exists in a compressed file.

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.