1. Gzip, can bzip2 directly compress the directory?

Source: Internet
Author: User

1. Gzip, can bzip2 directly compress the directory?

A: gzip and bzip2 cannot compress directories directly, compressed directories need to be packed and compressed using tar first.

2. Please write quickly, using gzip and bzip2 to compress and decompress a file command.

Answer: gzip:

Compression: gzip filename

Decompression: gzip-d filename.gz

BZIP2:

Compression: bzip2 filename

Decompression: bzip2-d filename.bz2

3. When the tar is packaged, how do you want to exclude multiple files or directories?

Answer: Tar--exclude file1--exclude file2--exclude dir1--exclude dir2-zcvf Newdir.tar olddir

4. Please experiment, if not add "-" is correct, such as tar zcvf 1.tar.gz 1.txt 2.txt?

A: You can properly compress:

[[email protected] test]$ ls

1 1.txt 2 2.txt 3 3.txt a.tar.gz

[Email protected] test]$ RM a.tar.gz

[[email protected] test]$ ls

1 1.txt 2 2.txt 3 3.txt

[Email protected] test]$ tar zcvf a.tar.gz 1 2 3

1/

2/

3/

[Email protected] test]$ TAR-TF a.tar.gz

1/

2/

3/

[Email protected] test]$

5. How to package and unpack with tar. tar.gz,. tar.bz2 compression pack?

Answer: tar.gz:

Compression: TAR-ZCVF a.tar.gz A

Decompression: TAR-ZXVF a.tar.gz

. TAR.BZ2:

Compression: TAR-JCVF b.tar.bz2 B

Decompression: TAR-JXVF b.tar.bz2

6. Find a larger file and use tar to separate the file into a. tar.gz and. tar.bz2 compression package, compare which package will be smaller, so that the conclusion is gzip compression effect is good or bzip2 compression effect is good?

A: The default compression level for BZIP2 is 9,gzip, which is 6. Generally speaking, bzip2 is better for compression, but it may be the opposite for some very small files.

[Email protected] test]$ Du-sh puma-em/

15M puma-em/

[Email protected] test]$ TAR-ZCF a.tar.gz puma-em/

[Email protected] test]$ TAR-JCF b.tar.bz2 puma-em/

[Email protected] test]$ du-sh a.tar.gz b.tar.bz2

2.6M a.tar.gz

2.2M b.tar.bz2

[Email protected] test]$

7. When packing and compressing with tar, what is the default compression level? Think about how you can change the compression level? (Note that tar itself does not have this function oh, you can try to split packaging and compression)

A: Tar itself is a packaged command, plus different parameters to use the compression function, such as add-Z using gzip compression function, at this time the compression level defaults to 6, such as add-j using the bzip2 compression function, the compression level by default is 9. To change the compression level, you can package with tar first, and then use the compression feature to specify compression level compression.  such as: TAR-CVF A.tar dir/; Gzip-2 A.tar


1. Gzip, can bzip2 directly compress the directory?

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.