Compression zip under Linux, extract unzip command details and examples

Source: Internet
Author: User
Tags rar rar extension uncompress

Example: compressing the contents of the current directory on the server as a xxx.zip file

Zip-r xxx.zip./*

Unzip the zip file to the current directory

Unzip Filename.zip

============================

Another: Some servers do not install the ZIP package does not execute the zip command, but basically can be used with the tar command, the example is as follows:

tar-zcvf/home/zdzlibs.tar.gz/home/zdz/java/zdzlibs/
============================

Linux zip command

Zip-r myfile.zip./*
All files and folders under the current directory are compressed into myfile.zip files, and-R indicates that all files in the subdirectory are compressed recursively.

2.unzip
Unzip-o-d/home/sunny Myfile.zip
Unzip the Myfile.zip file to/home/sunny/
-O: Overwrite the file without prompting;
-d:-d/home/sunny indicates that the file is extracted to the/home/sunny directory;

3. Other
zip-d Myfile.zip Smart.txt
To delete a smart.txt file in a compressed file
Zip-m Myfile.zip./rpm_info.txt
To add a rpm_info.txt file to a myfile.zip in a compressed file
-------------------------------------------------------------------------------

To compress a 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 recursively (recursively) include all files included in the Filesdir directory.

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 one after the other with a space interval:

Zip-r filename.zip file1 file2 file3/usr/work/school

The above command compresses the contents of the File1, File2, File3, and/usr/work/school directories (assuming this directory exists) and then puts them in the Filename.zip file.

A detailed description of the tar command

-C: Create compressed archives

-X: Unzip

-T: View content

-r: Append files to the end of a compressed archive file

-U: Update files in original compressed package

These five are stand-alone commands, which use one of the compression decompression, and can be used with other commands but only one. The following parameters are optional when compressing or extracting files as needed.

-C: Create compressed archives

-X: Unzip

-T: View content

-r: Append files to the end of a compressed archive file

-U: Update files in original compressed package

The following parameter-F is required

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

# 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,-T is to untie the meaning

Compression

TAR–CVF Jpg.tar *.jpg//package 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 compress them in gzip to generate a gzip compressed package named jpg.tar.gz

TAR–CJF jpg.tar.bz2 *.jpg//pack all JPG files in the directory into Jpg.tar and compress them in bzip2 to generate a bzip2 compressed package named jpg.tar.bz2

TAR–CZF jpg.tar.z *.jpg//pack all JPG files in the directory into Jpg.tar and compress them in compress 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 first

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

Extract

TAR–XVF File.tar//Unpacking the TAR Package

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

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

TAR–XZVF file.tar.z//Unzip 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 Extract with Uncompress

7, *.tar. Z Extract with Tar–xzf

8, *.rar with Unrar e decompression

9, *.zip with unzip decompression

A detailed description of the tar command in Linux (reproduced data)

April 17, 2008 Thursday 15:37

Tar command

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

Analysis of compressed files under Linux

For those who have just come into contact with Linux, it will definitely give Linux a bunch of different filenames to stun. Don't say it. For example, for compressed files, we know that there are only two types of compressed files that are most common under Windows, one is zip and the other is. Rap. But Linux is different, it has. GZ,. tar.gz, Tgz, bz2,. Z,. Tar and many other compressed filenames, in addition to the. zip and. rar under Windows can also be used under Linux, but there are too few people on Linux that use. zip and. rar. This article will be a summary of these common compressed files, I hope you do not get dizzy the next time you encounter these files.

Before summing up the various types of compressed files, first of all to understand the two concepts: 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 another of its tools to make this a lot of files first into a package, and then the original compression program compression.

The most common packaging program under Linux is tar, which is often referred to as the TAR package, and the tar package file commands are usually terminated with. Tar. After the tar package is generated, it can be compressed with other programs, so the basic usage of the tar command is first spoken:

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,-T is to untie the meaning

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 gzip. Here's an example:

# TAR-CJF all.tar.bz2 *.jpg

This command is to make all. jpg files into a tar package and compress them with bzip2 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 compress them with compress 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

In addition, there are methods for extracting common compressed files under window, zip and. Rar,linux.

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

# Unzip All.zip

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

2) for. rar

To process. rar files under Linux, you need to install RAR for Linux, which can be downloaded from the Web, but remember that RAR for Linux

Not for free; then install:

# TAR-XZPVF Rarlinux-3.2.0.tar.gz

# CD RAR

# make

This installs well, after installation has RAR and unrar these two programs, RAR is the compression program, Unrar is the decompression program. They have a lot of parameter options, here are just a brief introduction, still examples of its use:

# rar a All *.jpg

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

# Unrar E All.rar

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

To this, we have introduced the Linux tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip, unzip, RAR, Unrar and other programs, you should already be able to use them to. tar,. GZ,. tar.gz,. tgz,. bz2,. tar.bz2,. Z,. Tar. Z,. zip,. rar, 10 kinds of compressed files to extract, you should not need to download a software and do not know how to solve Linux under the worry. And the above methods are basically effective for UNIX.

This article describes the programs that are compressed under Linux, such as 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 kinds of 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.