Linux compression and decompression command detailed resolution _unix Linux

Source: Internet
Author: User
Tags bz2 pack rar rar extension uncompress

Linux zip command

Zip-r myfile.zip./*
Compresses all files and folders in the current directory into Myfile.zip files, and-R represents all files under a recursive compression subdirectory.

2.unzip
Unzip-o-d/home/sunny Myfile.zip
Extract the Myfile.zip file to the/home/sunny/
-O: Overwrite files without prompting;
-d:-d/home/sunny to extract the file into the/home/sunny directory;

3. Other
zip-d Myfile.zip Smart.txt
Delete smart.txt files in compressed files
Zip-m Myfile.zip./rpm_info.txt
Add Rpm_info.txt file to Myfile.zip in compressed file
-------------------------------------------------------------------------------

To compress the file using Zip, type the following command at the shell prompt:
Zip-r Filename.zip Filesdir

In this example, Filename.zip represents the file you created, and Filesdir represents the directory where you want to place the new zip file. The-r option specifies that you want to include all files included in the Filesdir directory recursively (recursively).

To extract the contents of a zip file, type the following command:
Unzip Filename.zip You can use the zip command to work with multiple files and directories at the same time by listing them individually and spacing by space:

Zip-r filename.zip file1 file2 file3/usr/work/school The above command compresses the contents of File1, File2, File3, and/usr/work/school directories (assuming this directory exists). Then put it in the Filename.zip file.

Tar command detailed

-C: Set up compressed files

-X: Decompression

-T: viewing content

-R: Appending files to the end of a compressed archive

-U: Updating files in original compressed package

These five are independent commands, compression decompression to use one of them, can be used with other commands but only one. The following parameters are optional when compressing or decompressing files as needed.

-C: Set up compressed files

-X: Decompression

-T: viewing content

-R: Appending files to the end of a compressed archive

-U: Updating files in original compressed package

The following parameter-F is required

-F: Use the file name, remember, this parameter is the last parameter, only the file name can be followed.

# 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----------T is untied

Compression

TAR–CVF Jpg.tar *.jpg//pack all JPG files in the directory into tar.jpg

TAR–CZF jpg.tar.gz *.jpg//pack all JPG files in the directory into Jpg.tar, and use gzip compression to generate a gzip compressed package named jpg.tar.gz

TAR–CJF jpg.tar.bz2 *.jpg//packages all JPG files in the directory into Jpg.tar, and uses bzip2 compression to generate a BZIP2 compressed package named jpg.tar.bz2

TAR–CZF jpg.tar.z *.jpg//packages all JPG files in the directory into Jpg.tar, and uses compress compression to generate a umcompress compressed package named Jpg.tar.z

RAR a jpg.rar *.jpg//rar format compression, you need to download RAR for Linux

Zip jpg.zip *.jpg//zip format compression, you need to first download zip for Linux

Extract

TAR–XVF File.tar//Extract tar Pack

TAR-XZVF file.tar.gz//Decompression tar.gz

TAR-XJVF file.tar.bz2//Decompression tar.bz2

TAR–XZVF File.tar.z//extract tar. Z

Unrar e file.rar//decompression rar

Unzip File.zip/Unzip zip

Summarize

1, *.tar with TAR–XVF decompression

2, *.gz with gzip-d or gunzip decompression

3, *.tar.gz and *.tgz with TAR–XZF decompression

4, *.bz2 with bzip2-d or with BUNZIP2 decompression

5, *.tar.bz2 with TAR–XJF decompression

6, *. Z with uncompress decompression

7, *.tar. Z with TAR–XZF decompression

8, *.rar with Unrar e decompression

9, *.zip with unzip decompression

Linux in the Tar command detailed (reproduced information)

Tar command

Tar can create archives for files and directories. With tar, users can create files for a particular file (backup files), change files in their files, or add new files to the file. Tar was originally used to create files on tape, and now users can create files on any device, such as a floppy disk. With the tar command, you can package a large number of files and directories into a single file, which is useful for backing up files or combining several files into a single file for easy network transmission. The tar on Linux is the GNU version.

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 back up a directory or some files, select 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.

Z use gzip to compress/decompress files, plus this option to compress the profile, but be sure to use this option to decompress when restoring.

Analysis of compressed files under Linux

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. Rap. 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.

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? In fact, many of the compressed programs in Linux can only be compressed for a single file, so that when you want to compress a large number of files, you have to use the other tools to make this large pile of files into a package, and then the original compression program compression.

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----------T is untied

The above is the most basic use of tar. In order to facilitate the packaging and unpacking of the user can compress or extract files, tar provides a special function. 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

This command is to make all. jpg files into a tar package and use gzip compression to generate a gzip-compressed 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 gzip. 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 way to extract them:

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 is a simple introduction, still give examples of 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 Web, but remember that RAR for Linux

Not free; then install:

# 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, these 10 compressed files for decompression, you should not need to download a software and do not 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 10 compressed files to operate

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.