How to decompress various compressed files under Linux __linux

Source: Internet
Author: User
Tags bz2 rar rar extension unpack uncompress compressed file types
For those who have just come in contact with Linux, it will certainly give Linux a lot of different file names to get dizzy. Let's just say, in the case of compressed files, we know that there are only two types of compressed files that are most common in Windows, one is zip and the other is. rar. But Linux is different, it has. GZ, tar.gz, tgz, bz2, and so on. Many compressed filenames, such as Z,. Tar, in addition to the. zip and. rar under Windows can also be used under Linux, but there are too few people using. zip and. rar in Linux. This article is to make a summary of these common compressed files, I hope you will not be dizzy next time you encounter these files Icon_smile.gif

Before you make a concrete summary of the various types of compressed files, first understand two concepts: packaging and compression. Packaging refers to a large pile of files or directories into a total file, compression is a large file through some compression algorithm into a small file. Why should we distinguish between these two concepts? It's actually a lot of pressure from Linux.
The Shrink program can only compress on a single file, so that when you want to compress a large stack of files, you have to use another tool to make the large pile of files into a package before compressing the original compression program.

The most common packaging program under Linux is tar, and the packages we use in the TAR program are often referred to as the TAR packets, and the TAR package file commands are usually ended with. Tar. After the tar package is generated, you can compress it with other programs, so let's start with the basic usage of the TAR command:

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, and here are some examples:

# TAR-CF All.tar *.jpg
This command is to make all. jpg files into a package named All.tar. -C indicates the creation of a new package,-f Specifies the file name of the package.

# TAR-RF All.tar *.gif
This command adds all the. gif files to the All.tar package. -R means to add a file.
# Tar-uf All.tar logo.gif
This command updates the logo.gif file in the original tar package All.tar, and-U is the meaning of the update file.

# TAR-TF All.tar
This command lists all the files in the All.tar package----------T is the list of files

# TAR-XF All.tar
This command is to solve all the files in the All.tar package------X is the meaning of the undo

The above is the most basic use of tar. In order to facilitate the packaging and unpack the user can compress or DecompressionFile, Tar provides a special feature. This is where tar can invoke other compression programs while packing or unpack, such as calling Gzip, bzip2, and so on.

1) Tar call gzip
Gzip is a compression program developed by the GNU organization, the file at the end of GZ is the result of gzip compression. The decompression program relative to Gzip is gunzip. Use the-Z parameter in tar to invoke gzip. Here are a few examples to illustrate:

# TAR-CZF all.tar.gz *.jpg
The command is to make all. jpg files into a tar package, and use gzip compression to generate a
Gzip compressed packets, package named all.tar.gz

# TAR-XZF All.tar.gz
This command is to untie the packets generated above.

2) Tar call bzip2
BZIP2 is a more compressed program,. bz2 end of the file is the result of bzip2 compression. The bzip2 relative to the decompression program is BUNZIP2. Use-j this parameter in tar to invoke gzip. Here are a few examples to illustrate:

# TAR-CJF all.tar.bz2 *.jpg
The command is to make all. jpg files into a tar package, and use bzip2 compression to generate a BZIP2 compressed package named all.tar.bz2

# TAR-XJF ALL.TAR.BZ2
This command is to untie the packets 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 compress relative to the decompression program is uncompress. Use the-Z parameter in tar to invoke compress. Here are a few examples to illustrate:

# TAR-CZF All.tar.z *.jpg
The command is to make all. jpg files into a tar package, and use compress compression to generate a uncompress compressed package named All.tar.z

# TAR-XZF All.tar.z
This command is to unlock the resulting package.

With the above knowledge, you should be able to unlock a variety of compressed files, the following for the TAR series of compressed files to make a summary:

1 for. Tar End of File
TAR-XF All.tar

2 for. GZ End of File
Gzip-d all.gz
Gunzip all.gz

3. Documents ending with. tgz or. tar.gz
Tar-xzf all.tar.gz
Tar-xzf all.tgz

4 for. bz2 End of File
Bzip2-d all.bz2
BUNZIP2 all.bz2

5) For tar.bz2 end of file
TAR-XJF all.tar.bz2

6) for. File at the end of Z
Uncompress all. Z

7 for. Tar.z End of File
Tar-xzf All.tar.z

In addition to the common compressed files under Windows. zip and. Rar,linux also have a corresponding method to extract it
Children

1) for. zip
Linux provides a zip and unzip program, ZIP is a compression program, unzip is the decompression program. Their parameters
A lot of options, here is a simple introduction, still give an example to illustrate its use:

# Zip All.zip *.jpg
This command compresses all. jpg files into a zip package
# Unzip All.zip
This command is to extract all the files in the All.zip

2) for. rar
To process A. rar file under Linux, you need to install RAR for Linux, which can be downloaded from the Internet, but remember that RAR for Linux is not free; can http://www.rarsoft.com/download.htm download rarfor Linux 3.2.0, and then installation

# TAR-XZPVF Rarlinux-3.2.0.tar.gz
# CD RAR
# make

This is installed, installed after the RAR and unrar these two programs, RAR is a compression program, Unrar is the decompression program. They have a lot of parameter options, here is a simple introduction, still give examples of its use:

# rar a All *.jpg
This command compresses all. jpg files into a RAR package named All.rar, which automatically attaches the. rar extension to the package name.

# Unrar E All.rar
This command is to extract all the files in the All.rar

In this context, we have introduced Linux under the TAR, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip, unzip, RAR, Unrar and other programs, you should have been able to use them for. Tar,. GZ,. tar.gz, tgz, bz2, tar.bz2,. Z,. Tar. Z,. zip,. rar 10 compressed files for decompression, you should not need to download a SoftwareAnd don't know how to untie under Linux and worry. And the above method is also basically effective for UNIX.

This article describes the programs in the Linux compression program tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip, unzip, RAR, Unrar, and how to use them for. Tar,. GZ,. tar.gz, tgz,. bz2,. tar.bz2,. Z. Tar. Z,. zip,. rar, these 10 compressed files to operate.

Detailed usage of Linux tar commands and common compressed file types and decompression


Syntax: tar [main options + auxiliary options] File or directory

When using this command, the main option is required, it tells Tar what to do, the auxiliary option is auxiliary, and can be selected.

Main options:

C Create a new profile. If the user wants to BackupA directory or some files, you should choose this option.

R Append files to archive to the end of the file. For example, the user has made a backup file, and found that there is a directory or some files forgotten to back up, you can use this option to append the forgotten directories or files to the backup file.

T lists the contents of the profile to see which files have been backed up.

U update files. That is, replace the original backup file with the new file, and append it to the end of the backup file if the file you want to update cannot be found in the backup file.

X releases the file from the profile.

Accessibility Options:

b This option is set for the tape drive. followed by a number to indicate the size of the block, the system preset is 20*512 bytes.

F Use an archive file or device, this option is usually required.

K to save a file that already exists. For example, we restore a file, in the process of restoration, encountered the same file, will not be overwritten.

m when restoring the file, set all files to the current change time.

M to create a multiple-volume profile for storage on several disks.

V Detailed report of tar processing file information. Without this option, TAR does not report file information.

W each step is required to confirm.

F This parameter is really a must, or you can not find your tar file
In fact, when the use of the feeling of some superfluous, since it is required, then simply solidified to tar the command itself is AH
But it is not the case, if you do not use this parameter, he will tell you what "file does not exist" error
It's called a poorly designed software (or command).

V is also important, and you can usually see the details

So it's usually the order to construct the tar bag.
Tar CVF tar package name. tar directory, file list
The so-called directory file list is a space to separate files and directories

And the tar packets are usually an order.
Tar xvf tar package name. tar directory, file list

The tar file is a collection of several files and/or directories in one file. This is the best path to create backup and archive.
The options used in tar are:
-c-Create a new archive.
-f-when used with the-C option, the created tar file uses the file name specified by the option, and when the-X option
When used together, the archive specified by this option is released.
-t-displays a list of files included in the tar file.

-v-Displays the archive progress of the file.

-x-extracts files from the archive.

-z-uses gzip to compress the tar file.

-j-uses bzip2 to compress the tar file.

To create a tar file, type:

TAR-CVF Filename.tar Directory/file

You can use the tar command to work with multiple files and directories at the same time by listing them individually and spacing by space:

TAR-CVF Filename.tar/home/mine/work/home/mine/school

The above command puts all the files in the work and school subdirectories under the/home/mine directory into the current
A new file called Filename.tar in the directory.

To list the contents of the tar file, type:
TAR-TVF Filename.tar

To extract the contents of the Tar file, type
TAR-XVF Filename.tar

This command does not delete the tar file, but it will release the content that is being archived
Copy to the current workDirectory and keep Any of the files used by the archive
Directory structure. For example, if this tar file contains a name called
Bar.txt file, and this file is contained in the foo/directory, then,
Extracting the archive will cause you to create in your current working directory
foo/directory, which contains bar.txt files

Tar defaults to not compress files.

To create a file that uses tar and bzip to archive compression, use the-J option:
TAR-CJVF filename.tbz File

The above command creates an archive file and then compresses it into a filename.tbz file. If you extract the Filename.tbz file using the BUNZIP2 command, the filename.tbz file is deleted, followed by the Filename.tar file.

You can also use a command to extend and deallocate bzip tar files:
TAR-XJVF FILENAME.TBZ

To create a file that is archived and compressed with tar and gzip, use the-Z option:
TAR-CZVF filename.tgz File

This command creates the archive file Filename.tar, and then compresses it into a filename.tgz file (the file Filename.tar is not retained).
If you use the Gunzip command to extract the Filename.tgz file, the filename.tgz file is deleted and is
Replace with Filename.tar.

You can extend the gzip tar file with a single command:
TAR-XZVF filename.tgz




The following is a classic example of online collection

Example 1: The/home directory includes its subdirectories to do all the backup files, the backup file name is Usr.tar.

$ tar cvf usr.tar/home

Example 2: The/home directory includes its subdirectories to do all the backup files, and compression, backup file name usr.tar.gz.

$ tar czvf usr.tar.gz/home

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

$ tar xzvf usr.tar.gz

Example 4: View the contents of the Usr.tar backup file and display it on the monitor in a split-screen manner.

$ tar TVF Usr.tar | More

To back up a file to a specific device, simply use the device name as the backup file name.

Example 5: The user creates a backup file on the floppy disk of the/DEV/FD0 device and copies all the files in the/home directory to the backup file.

$ tar Cf/dev/fd0/home

To recover files on a device disk, use the XF option:

$ tar xf/dev/fd0
Two files into a tar package
Tar cvf log.tar log.0000000007 dbversion

1. Compress a set of files as a tar.gz suffix.
# tar CVF backup.tar/etc
#gzip-Q Backup.tar
Or
# tar Cvfz backup.tar.gz/etc/
Tar zxvf XXXX.tar.gz

Tar jxvf XXXX tar.bz2

2. Release a file with a suffix of tar.gz.
#gunzip backup.tar.gz
#tar XVF Backup.tar
Or
# tar Xvfz backup.tar.gz

3. Complete compression with one command
#tar CVF-/etc/| GZIP-QC > Backup.tar.gz

4. Complete the release with one command
# gunzip-c Backup.tar.gz | Tar xvf-

5. How to undo tar. Z's file.
# tar Xvfz backup.tar.z
Or
# uncompress Backup.tar.z
#tar XVF Backup.tar

6. How to unlock the. tgz file.
#gunzip backup.tgz

7. How to compress and decompress. bz2 package.
#bzip2/etc/smb.conf
This will compress the file smb.conf into smb.conf.bz2
#bunzip2/etc/smb.conf.bz2
This will restore smb.conf.bz2 to smb.conf in the current directory
Note:. BZ2 compression format is not very common, you can man bzip2

Linux Common compressed file types and decompression
Compressing and packaging files

. bz2-use the bzip2 command to compress files, you can use bzip2-d filename to unpack

. gz-files that are compressed using the gzip command, you can use gunzip-d filename to unpack

. tar-use the Tar-packaged file, the Tarball file, to unpack with the tar XF filename

. tbz-files that are compressed with the BZIP2 command after the package is finished with tar, you can use tar jxf filename to unpack

. tgz-files that are compressed with the GZIP command after the package is finished with tar, you can use tar zxf filename to unpack

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.