Linux Basic Tutorial 32-Unzip command

Source: Internet
Author: User
Tags create directory gz file unpack ziparchive

? ? After compressing files to improve data transmission efficiency, reduce transmission bandwidth, management of backup data has a very important function, so file compression decompression skills become the necessary skills. Compared to the file decompression tool in Windows Flowers Zhengyan, the Unzip tool in Linux is much less, the commonly used decompression commands are gzip,bzip2,tar,zip and so on.

gzip command

gzip only for ordinary files compression and decompression, for folders, symbolic links, etc. are not supported . The basic syntax is as follows:

gzip [选项] [文件]

The common parameters are as follows:

Parameters Description
-D,--decompress Unzip the file
-F,--force Compress/Unzip files to force overwrite files that already exist
-L,--list Displays information about the compressed package, such as the pre-compression size, size after compression, compression ratio, and so on
-R,--recursive Recursively compress files in all files and subdirectories in the specified directory, compressing each file into one GZ file
-T,--test Check the integrity of compressed files
-V,--verbose Show detailed procedures
-V,--version Display version Information

Compression speed and compression strength

? ? When compressing a file, you can adjust the compression time and compression ratio according to the actual need of different compression speed and compression strength. There are 9 compression levels available in gzip.

    • -1: Represents the fastest compression, but the compressive strength is not high
    • -9: Represents the highest compression strength, but the compression speed is slow
    • -6: gzip Default value

An example of gzip is shown below:

    • 1. Adding compressed Files
[[email protected] Python-3.7.0]# du -sh Python-3.7.0189M    Python-3.7.0[[email protected] Python-3.7.0]# gzip -r Python-3.7.0[[email protected] Python-3.7.0]# du -sh Python-3.7.064M     Python-3.7.0[[email protected] Python-3.7.0]# ll总用量 10856-rw-rw-r--  1 root     root    3731 6月  27 11:07 aclocal.m4.gzdrwxr-xr-x  5 root     root      82 7月  20 12:43 build-rw-rw-r--  1 root     root   13214 6月  27 11:07 config.guess.gz-rw-r--r--  1 root     root   38624 7月  20 12:48 config.log.gz
    • 2. Compress the TAR package
[[email protected] Python-3.7.0]# gzip Python-3.7.0.tar[[email protected] Python-3.7.0]# ll -h总用量 52M-rw-r--r-- 1 root root 52M 7月  24 14:13 Python-3.7.0.tar.gz
    • 3. Unpack the Compressed package
gzip -d Python-3.7.0.tar.gz
    • 4. Display the information of compressed package
[[email protected] Python-3.7.0]# gzip -l Python-3.7.0.tar.gz         compressed        uncompressed  ratio uncompressed_name           53670458           190464000  71.8% Python-3.7.0.tar
Bzip2
bzip2与gzip非常类似,区别在于gzip压缩和解压均是同一个命令,而bzip2压缩命令为bzip2,解压缩命令为bunzip2
Tar command

The tar command is the most used command in Linux, and the base basic syntax is as follows:

tar [选项] [文件]

The common parameters are as follows:

Options Description
-A,--catenate To add a compressed package to a compressed package
-C,--create New Compressed Package
-C,--directory=dir Specifying the extracted directory
-D,--diff Compare the difference between a compressed package and a file system
--delete To delete a specified file from a compressed package
-R,--append Append file to end of file
-T,--list Display the directory structure in a compressed package
-U,--update To add a newer file to a compressed package only
-X,--extract Unpack the Tarball
-F,--file=archive Specifying compressed Files
-V,--verbose Show detailed procedures
-j,--BZIP2 Support BZIP2
-Z,--gzip Support for Gzip
--overwrite If the file already exists, replace it when extracting

The things to note in using tar are as follows:

    • 1. The main option parameters are as follows:
-c -x -t -r -u以上这5个参数同时只能出现一个,不能同时出现多个
    • 2. Auxiliary options
-f :一般情况需要将该参数放置在最后位置,后面紧跟文件名

Examples of tar are shown below:

    • 1. Add compressed files to the current directory
[[email protected] ~]# tar -cf Alltxt.tar *.txt
    • 2. View the contents of the compressed package
[[email protected] ~]# tar -tf Alltxt.tarin.txtout.txtpackstack-answers-20180710-091950.txtpackstack-answers-20180710-092155.txtpackstack-answers-20180710-100538.txt
    • 3. Add a compressed package to the package
[[email protected] ~]# tar -cf Alltxt.tar *.txt[[email protected] ~]# tar -cf Allbak.tar *.bak[[email protected] ~]# tar -Af Alltxt.tar Allbak.tar[[email protected] ~]# tar -tf Alltxt.tarin.txtout.txtpackstack-answers-20180710-091950.txtpackstack-answers-20180710-092155.txtpackstack-answers-20180710-100538.txtappend.txt.bak
    • 4. Add files to the ZIP package
[[email protected] ~]# tar -rf Alltxt.tar out[[email protected] ~]# tar -tf Alltxt.tarin.txtout.txtpackstack-answers-20180710-091950.txtpackstack-answers-20180710-092155.txtpackstack-answers-20180710-100538.txtappend.txt.bakout/out/out.txtout/eip.sh
    • 5. Update the files in the compressed package
[[email protected] ~]# tar -uf Alltxt.tar append.txt.bak
    • 6. Extract files to the specified directory
[[email protected] ~]# tar -xf Python-3.7.0.tar  -C TarTest/
    • 7. Unzip the specified file in the package
[[email protected] Python-3.7.0]# tar -xf Python-3.7.0.tar Python-3.7.0/pyconfig.h[[email protected] Python-3.7.0]# tree Python-3.7.0Python-3.7.0└── pyconfig.h0 directories, 1 file
Zip command

Similar to bzip2, zip is used to compress files, while unzip is used to extract files. Its basic syntax is as follows:

zip [选项] [指定文件名] [压缩文件或路径]uzip [选项] [压缩包名称]
    • The zip common parameters are as follows:
Options Description
-C,--entry-comments Add comments to a compressed file
-D,--delete To delete a specified file from a compressed package
-D Compressed package does not create directory name
-F,--freshen Similar to parameter-U, not only does it update existing files, but it also adds files that do not have a compressed package
-I files/--include files Add the specified file only to the compressed package
-M,--move To add the original file to the compressed package delete the original file
-O Output-file
-Q,--quiet Silent mode
-R,--recurse-paths Recursive processing of specified directories and subdirectories
-T,--test Check the integrity of the compressed package
-U,--update Replace newer file updates in a compressed package
-V,--verbose Show detailed procedures
-X files/--exclude files Add an exclusion when compressing a file
-# ( -0~-9) Set the compression level,-0: Do not compress the file,-1: The fastest compression speed, 9: The best compression strength, the default is 6
    • Unzip common parameters
Options Description
-L Displaying content in a compressed package
-T Check the integrity of the compressed package
-O Force overwrite files that already exist without prompting
-j Do not process the original directory path in the compressed file
-D Exdir Specify Unzip Directory

An example of Zip/unzip is shown below:

    • 1. Add a compressed package
[[email protected] Python-3.7.0]# zip -r Python-3.7.0.zip Python-3.7.0
    • 2. Unpack the compressed package
unzip -d /tmp/ Python-3.7.0.zip
    • 3. Check the integrity of the compression package
[[email protected] Python-3.7.0]# unzip -t Python-3.7.0.zipArchive:  Python-3.7.0.zip    testing: Python-3.7.0/            OK    testing: Python-3.7.0/install-sh   OK    ...    testing: Python-3.7.0/pybuilddir.txt   OKNo errors detected in compressed data of Python-3.7.0.zip.
    • 4. Display the contents of the compressed package
[[email protected] Python-3.7.0]# unzip -l Python-3.7.0.zipArchive:  Python-3.7.0.zip  Length      Date    Time    Name---------  ---------- -----   ----        0  07-20-2018 12:50   Python-3.7.0/     7122  06-27-2018 11:07   Python-3.7.0/install-sh   101855  06-27-2018 11:07   Python-3.7.0/setup.py        0  07-20-2018 12:37   Python-3.7.0/.vsts/ 13965984  07-20-2018 12:50   Python-3.7.0/python       26  07-20-2018 12:50   Python-3.7.0/pybuilddir.txt---------                     -------186791269                     4771 files
    • 5. Delete the files specified in the compressed package
[[email protected] Python-3.7.0]# zip Python-3.7.0.zip -d Python-3.7.0/*.odeleting: Python-3.7.0/Modules/config.odeleting: Python-3.7.0/Modules/getpath.odeleting: Python-3.7.0/Modules/main.o

This article is posted on the subscription number, such as your friends like my article, you can also follow my subscription number: Woaitest, or scan the following QR code to add attention:

Linux Basic Tutorial 32-Unzip command

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.