File compression gzip/gunzip/Bzip2/bunzip2/tar

Source: Internet
Author: User

Gzip gunzip common compressed files

Simple commands-simple operations. Linux compression Tool

[[Email protected] huxiaoming] # gzip 123.txt # gzip directly compresses the source file without retaining the source file #

[[Email protected] huxiaoming] # ls

123.txt.gz 2.txt shuzu. Sh software_list.log

[[Email protected] huxiaoming] # gunzip 123.txt.gz # vice versa #

[[Email protected] huxiaoming] # ls

1 123.txt 2.txt shuzu. Sh software_list.log

Bzip bunzip-higher compression rate, available in new Linux versions

[[Email protected] huxiaoming] # Bzip2 123.txt

[[Email protected] huxiaoming] # ls

1 123.txt.bz2 2.txt shuzu. Sh software_list.log

[[Email protected] huxiaoming] # bunzip2 123.txt.bz2

[[Email protected] huxiaoming] # ls

1 123.txt 2.txt shuzu. Sh software_list.log

Tar-file archiving

Examples:

Tar-CF archive.tar Foo bar # create archive.tar from files Foo and bar.

Tar-tvf archive.tar # list all files in archive.tar verbosely.

Tar-XF archive.tar # extract all files from archive.tar.

Option and parameter:-C: Create a package file. You can use-V to check the file name (filename)-T in the package process. Check the file names contained in the package file, focus on checking the 'file name'.-X: The unpack or decompress function can be used with-C (uppercase) To uncompress a file in a specific directory. Note that-C, -T and-x cannot appear in a string of command columns at the same time. -J: compress/decompress the file with Bzip2 support. In this case, the file name is * .tar.bz2-Z. Compress/decompress the file with gzip support: at this time, the file name should be * .tar.gz-V: During the compression/decompression process, the file name being processed should be displayed! -F filename: name of the file to be processed immediately after-F! -F is recommended to write an option separately! -C Directory: This option is used for decompression. to decompress the package in a specific directory, you can use this option. -P: retains the original permissions and attributes of the backup data. It is often used in backup (-C) important settings-P: retains the absolute path, that is, to allow the backup data to contain the root directory; -- exclude = file: During the compression process, do not package the file!


For example, if I want to compress all the files under/etcinto an etc.tarpackage, use the high compression tool bzip2to compress the file with the suffix .bz2 in/home/huxiaoming.


[Email protected] huxiaoming] # tar cvfj/home/huxiaoming/etc.tar.bz2/etc

650) This. width = 650; "Title =" Clipboard "style =" border-top: 0px; border-Right: 0px; Background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; padding-Right: 0px; "Border =" 0 "alt =" Clipboard "src =" http://img1.51cto.com/attachment/201408/11/8976580_1407764322HQ1i.png "Height =" 18 "/>

Here we can see the advantage of using the J parameter, the compression ratio is almost 4 times the default

650) This. width = 650; "Title =" Clipboard [1] "style =" border-top: 0px; border-Right: 0px; Background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-Right: 0px; "Border =" 0 "alt =" Clipboard [1] "src =" http://img1.51cto.com/attachment/201408/11/8976580_14077643222XhB.png "Height =" 66 "/>

  • Compression: name of the file or directory to be compressed by tar-JCV-F filename.tar.bz2

  • Query: tar-jtv-F filename.tar.bz2

  • Decompress: tar-jxv-F filename.tar.bz2-C directory to be decompressed

Three Axes

To decompress the tar command, we recommend that you list the-F parameter separately.

[[Email protected] huxiaoming] # tar-jxv-f/home/huxiaoming/etc.tar.bz2-C/home/huxiaoming/backupetc

Review the previous find command to delete the tar file just created

[[Email protected] huxiaoming] # Find/home/huxiaoming/-name "* tar *"-OK RM {}\;

<RM.../home/huxiaoming/etc.tar.bz2>? Yes

<RM.../home/huxiaoming/etc.tar>? Yes

<RM.../home/huxiaoming/backupetc/etc/init/start-ttys.conf>? N

<RM.../home/huxiaoming/backupetc/etc/RedHat-LSB/lsb_start_daemon>? N

<RM.../home/huxiaoming/backupetc/etc/xdg/autostart>? N

<RM.../home/huxiaoming/backupetc/etc/dbus-1/system. d/upstart. conf>? N

<RM.../home/huxiaoming/backupetc/etc/SELinux/targeted>? N

<RM.../home/huxiaoming/backupetc/etc/event. d/CK-log-system-Restart>? N

<RM.../home/huxiaoming/backupetc/etc/event. d/CK-log-system-Start>? N

<RM.../home/huxiaoming/backupetc/etc/libreport/events. d/tarball_event.conf>? N

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.