Linux command (+): Zip/unzip command-Package compression

Source: Internet
Author: User

Zip command

Function description

Zip Program is a file compression tool is also a file archiving tool, files or directories can be compressed or decompressed, compressed format for zip. In Linux systems, Gzip is the main compression instruction, and BZIP2 is the second only. Linux users primarily use zip programs to swap files with Windows systems, rather than using them for compression or archival purposes. Use the following:

Zip [options] Compressed file name a list of documents that need to be compressed

Unzip [options] compress file names

Common parameters

Options Description
Zip command
-R Recursive compression, compressing all files and subdirectories under the specified directory
-D To delete a specified file from within a compressed file
-I "File list" Compress only files in the file list
-X "File list" Files specified in the Queued files list when compressing
-U Update files into compressed files
-M After compressing the file into a compressed file, delete the original file, that is, the horse file is moved to the compressed file
-F Try to repair a corrupted compressed file
-T Check that each file within the compressed file is correct
- # The compression level is a number between 1-9
Unzip command
-X "File list" Unzip the file, but does not include the file specified in the file list
-T Test the compressed file for damage, and do not understand the pressure
-V View the details of the compressed file, including the file size, filename, and compression ratio contained in the compressed file, and
-N Do not overwrite files that already exist while extracting
-O Overwrite files that already exist while extracting, and do not require user confirmation
-D directory Name Unzip the compressed file into the specified directory

Example

compress all files and directories in the test directory

[Email protected] app]# zip -9r test.zip test/

compression of all files and subdirectories in the test directory, except for *.gz files, the compressed files are saved in the current directory

[[E Mail protected] app]# ls-l test

Total usage 216

-rw-r--r--. 1 root root    181 November 23 17:07 99.sh

-rw-------. 1 root root  11595 November 17:07 messages

-rw-r--r--. 1 root root   1149 November 17:07 messages2.gz

-rw-r--r--. 1 root root   1202 November 17:07 messages.gz

-rw-r--r--. 1 root root 14 3538 November 17:07 shell.txt

-rw-r--r--. 1 root root  48218 November 17:07 shell.txt.bz2

[[Email protec Ted] app]# zip-r test3.zip test #没有压缩 *.gz files

  adding:test/(stored 0)

  adding:test/99.sh (deflated 30%)

  adding:test/ Messages (deflated 90%)

  Adding:test/shell.txt (deflated 62%)

  ADDING:TEST/SHELL.TXT.BZ2 ( Deflated 0)

Use the- d parameter to remove the Test/shell.txt file from the compressed package from the above Test3.zip

[Email protected] app]# zip test3.zip- d test/shell.txt

Deleting:test/shell.txt

using the- u parameter, the modified/test/99.sh file is updated to update the changed information into the Test3.zip package

[[email protected] app]# zip- u test3.zip/test/99.sh

updating:test/99.sh (deflated 30%)

If you have more files in the test directory, you can update them all to Test3.zip using the following method

[Email protected] app]# zip -ru test3.zip/test/

Extract the Test3.zip compressed files to the/tmp directory, and in the decompression process, such as if the same file will be overwritten directly, do not require user confirmation

[Email protected] app]# unzip - o test3.zip-d/tmp/

[Email protected] test]# pwd

/tmp/test

[[email protected] test]# ls

99.sh Messages shell.txt.bz2


Learn from:

Karst "Progressive Linux"


This article is from the "Zhao Dongwei blog" blog, make sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1876259

Linux command (+): Zip/unzip command-Package compression

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.