Linux Study Notes (7) common Linux commands: compression and decompression commands, learning notes compression and decompression

Source: Internet
Author: User

Linux Study Notes (7) common Linux commands: compression and decompression commands, learning notes compression and decompression
(1) gzip

The gzip command is used to compress files. The original English meaning is GNU zip. The path is/bin/gzip. The syntax format is as follows:

Gzip [file]

The file format is .gz.

For example, copy the services file under the/etc directory to the/tmp directory and compress it with gzip.

[root@localhost tmp]# cp /etc/services services[root@localhost tmp]# lsservices[root@localhost tmp]# gzip services[root@localhost tmp]# lsservices.gz

Note: gzip can only compress files, but cannot compress directories. The gzip command does not retain the source files, as shown in the preceding example.

(2) gunzip

The gunzip command is used to extract files. The original English meaning is GNU unzip. The path is/bin/gunzip. The syntax format is:

Gunzip [compressed file]

For example, decompress the newly created compressed file.

[root@localhost tmp]# gunzip services.gz[root@localhost tmp]# lsservices

Note: You can also use gzip-d to decompress the file. After gunzip is executed, the source file is not retained.

(3) tar

The tar command is used to package directories. The path is/bin/tar. The syntax format is as follows:

Tar option [-zcf] [compressed file name] [Directory]

.

For example, create the test/test1 and test/test2 directories under the/tmp directory, and then package the test directory.

[root@localhost tmp]# mkdir -p test/test1 test/test2[root@localhost tmp]# tar -czvf test.tar.gz testtest/test/test2/test/test1/[root@localhost tmp]# ls -ltotal 636-rw-r--r--. 1 root root 641020 Jan  1 22:17 servicesdrwxr-xr-x. 4 root root   4096 Jan  1 22:25 test-rw-r--r--. 1 root root    134 Jan  1 22:26 test.tar.gz

The tar decompression syntax is as follows:

Tar-xzvf [compressed file]

Among them, the-x option indicates unpacking, the-v option indicates displaying details, the-f option indicates specifying the decompression file, and the-z option indicates decompression.

For example, delete the created testobject and decompress test.tar.gz.

[root@localhost tmp]# rm -rf test[root@localhost tmp]# lsservices  test.tar.gz[root@localhost tmp]# tar -xzvf test.tar.gztest/test/test2/test/test1/[root@localhost tmp]# lsservices  test  test.tar.gz
(4) zip

The zip command is used to compress files or directories. The path is/usr/bin/zip. The syntax format is as follows:

Zip option [-r] [compressed file name] [file or directory]

In this example, the file format is. Zip.

For example, zip the services file:

[root@localhost tmp]# zip services.zip services  adding: services (deflated 80%)[root@localhost tmp]# lsservices  services.zip  test  test.tar.gz

Note: The zip format exists in both Linux and Windows. The compression ratio is not very high.

(5) unzip

The unzipcommand is used to extract files in the. ZIP format. The path is/usr/bin/unzip. The syntax format is:

Unzip [compressed file]

Example: Decompress the services.zip File

[root@localhost tmp]# unzip services.zipArchive:  services.zipreplace services? [y]es, [n]o, [A]ll, [N]one, [r]ename:

If the source file exists, ask whether to replace it during decompression.

(6) bzip2

Bzip2 is an upgraded version of gzip and is also used to compress files. Its path is/usr/bin/bzip2. Its Syntax format is:

Bzip2 option [-k] [file]

The-k option will generate the compressed file and keep the source file. The file format is .bz2.

You can save the directory as A. bz2 file by using the tar command in the following format:

Tar option [-cjvf] [compressed file name] [Directory]

Among them, the file "-July" is compressed as the. bz2 file.

For example, use the bzip2 command to compress the services file and then compress the test directory.

[root@localhost tmp]# bzip2 -k services[root@localhost tmp]# lsservices  services.bz2  services.zip  test  test.tar.gz[root@localhost tmp]# tar -cjvf test.bz2 testtest/test/test2/test/test1/[root@localhost tmp]# lsservices  services.bz2  services.zip  test  test.bz2  test.tar.gz
(7) bunzip2

The bunzip2command is used to decompress the. bz2 file. The path is/usr/bin/bunzip2. Its Syntax format is:

Bunzip2 option [-k] [File compression]

-K indicates that the source file is retained after decompression.

You can also decompress the. bz2 file using the tarcommand in the following format:

Tar option [-xjvf] [compressing files]

For example, delete the services file and the test folder, and decompress them separately:

[root@localhost tmp]# rm -rf services test[root@localhost tmp]# lsservices.bz2  services.zip  test.bz2  test.tar.gz[root@localhost tmp]# bunzip2 services.bz2[root@localhost tmp]# tar -xjvf test.bz2test/test/test2/test/test1/[root@localhost tmp]# lsservices  services.zip  test  test.bz2  test.tar.gz

Related Article

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.