Multiple Linux compression methods

Source: Internet
Author: User

After a long period of development in Linux, many users have learned about linux compression. Here I will share my personal understanding and discuss it with you. There are many linux compression tools. The following are commonly used compression tools and their generated file suffixes: gzip/gunzipsuffix: .gz; compress/uncompress suffix. z; zip/unzipsuffix: .zip; bzip2/bunzip2suffix: .bz2; lha, Suffix. lzh. Linux compression tools are most commonly used, including gzip, zip, and bzip2. The following describes the three most commonly used compression tools.

1.gzip command
◆ There are two purposes to compress files: one is to reduce the storage space, and the other is to reduce the network overhead for file transfer over the network. Gzip is the most commonly used software compression tool in Linux. Enter the mangzip command on the Linux terminal to drop the gzip help document. The command format is: gzip [Option] compressed or decompressed file name.
◆ The following example shows how to use the gzip command to compress all the files in the current directory and display the compression ratio. It shows that the original files have been replaced: # gzip-v *, the-v parameter indicates the compression ratio and file name. Hosts file. For this reason, linuxjust uses the Tartar command to pack the hosts file or file into a file, and then compress it into a .gz file. Next, we will extract the compressed files in the current directory and list the detailed information: # gzip-dv *.
◆ In addition, the content of the compressed file is displayed. You can use the gzip command with the-l parameter to display the content of the gz file. This only shows the file content and does not actually decompress the file: # gzip-l *.
In addition, you can directly embed the gzipcommand in the tarcommand to directly process the hosts file or folder into a .tar.gz file. In this process, the system first packs the hosts file or file into a tar.tar.gz file, and then compresses the generated .tar.gz file. For example, pack all the files in the current directory and compress them into gong.tar.gz and display the processing progress: #tarcvfzgong.tar.gz ./*.

2. zip/unzip command
◆ The zip program is located in the/usr/bindirectory. You can compress the file into a. zip file to save hard disk space, and uncompress the linux compressed file when necessary. The unzip command is used to decompress the compressed file. The zip command is used as follows:

◆ Zip [Option] indicates the type of operation to be completed. The compressed file name is a valid file name with the suffix zip, files or folders to be compressed indicate the files or folders to be compressed. They can be multiple files or folders.

◆ The following example shows how to use this command to compress files or folders. For example, if all the files and folders under the current directory are compressed into a gong.zip file,-r indicates recursively compressing all the files under the subdirectory: unzip zip-rgong.zip ./*. You can use the "-v" parameter option to view the content of the zip file. This is similar to the tar command with the "t" parameter option. Only the former is used to display the content of the compressed zip file, and the latter is used to display the content of the tar file. It is similar to the Tartar command line with Tsung, And the zipcommand line with vzip cannot be decompressed. For example, the content of the gong.zip file is zip-vgong.zip.

◆ You can use the zip command with the-d parameter option to delete a file from the zip compressed file, and use the zip command with-m to add a file to the zip compressed file. For example, delete the smart.txt file in the compressed file: unzip zip-dgong.zipsmart.txt.pdf to the compressed file: unzip zip-mgong.zip./rpm_info.txt.

◆ In addition, The unzip command is used to decompress a compressed file with the extension zip. In Windows, files compressed with the compression software Winzip can also be decompressed using the unzip command in Linux. The unzip command syntax is as follows: unzippered compressed file name. Zip. Common usage of the unzip command is: unzip unzipgong.zipto decompress gong.zipto the current directory. unzip unzip-ntext.zip-d/tmpto decompress the text.zip file under the current directory. The-n parameter specifies that the original file is not overwritten, -d/tmp indicates to extract the file to the/tmpdirectory. Unzip unzip unzip-vtext.zip to display the content of the text.zip compressed file in the current directory ).

3.bzip2 command
◆ Bzip2 is a lossless compression software with high-quality data compression capabilities. It can compress files to the original 10% to 15%, and the compression speed and decompression speed are very high, so it is widely used in Linux compression software.
When bzip2reads the file name and name from the command line, each file is replaced by a compressed file named "original file name .bz2. Each compressed file has the same modification time and permissions as the original file. If possible, it also has the same owner. Therefore, these features are restored correctly during decompression.
◆ The specific operation is as follows, for example, with the bzip2 command to compress all files in the current directory, with the bunzip2-z * will get the same effect: # bzip2 *. Another example is to use the bunzip2command to decompress all the files in the current directory. One file, free.txt, is not suffixed with bz2: # bunzip2.

  1. Brief Introduction to Linux releases
  2. Linux wireless network technology: GPRS, GSM
  3. Linux fsck data error Disaster Response Plan
  4. 8 practical and interesting Bash command prompt lines in Linux
  5. Linux memory management-discontinuous physical address allocation (vmalloc)

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.