Linux compression decompression tools-Daily learning

Source: Internet
Author: User
Tags bz2 gz file

date:2017-04-08

Linux compression decompression tools-Daily learning

command (corresponding format): gzip (. gz) bzip2 (. bz2) XZ (. xz) compress (. z) tar (. tar)

1.gzip

Syntax: gzip option FILE

Common options:-D-#-C

(1)-D (DECOMPRESSIOM): Unzip

There are two ways to decompress: "Gizp-d FILE" and "Gunzip FIEL"

eg

tmp]# LS-LH Messages (-h:human-readdble readable function: Conversion of file size units )
-rw-r--r--. 1 root root 361K Apr 8 04:53 messages (source file size is 361k)
tmp]# gzip Messages (zipped file)
tmp]# LS-LH messages.gz (compressed file added. gz format)
-rw-r--r--. 1 root root 8.2K Apr 8 04:53 messages.gz (the file size after compression is 8.2k)
tmp]# gzip-d messages.gz (-d mode unzip file)
tmp]# LS-LH Messages
-rw-r--r--. 1 root root 361K Apr 8 04:53 messages (uncompressed file size changed to 361k)

(2)-#: Specify compression ratio, default is 6 (can fetch range of 1-9)

(3)-C: Save the source file while compressing and output the compressed content to the terminal, usually with the redirected output ">".

Command behavior when used together: gizp-c source file > Compressed text. GZ (does not output to the terminal, the compressed file is output to the specified text)

2.bzip2

Syntax: bzip2 option FILE

Common options:-D-#-K

(1)-D (DECOMPRESSIOM): Unzip

There are two ways to decompress: "Bizp2-d FILE" and "Bunzip2 FIEL" (IBID.)

(2)-#: Specify compression ratio, default is 6 (can fetch range of 1-9)

(3)-K (keep): The compressed file is saved automatically to the. bz2 (file created in this format) while the source file is kept in compression. (unlike GIZP, you do not need to redirect the output to save the compressed file)

3.xz

Syntax: bzip2 option FILE

Common options:-D-#-K

(1)-D (DECOMPRESSIOM): Unzip

There are two ways to decompress: "Xz-d FILE" and "Unxz FIEL"

(2)-#: Specify compression ratio, default is 6 (can fetch range of 1-9)

(3)-K (keep): The compressed file is saved automatically to the. bz2 (file created in this format) while the source file is kept in compression. (unlike GIZP, you do not need to redirect the output to save the compressed file)

4.compress (compressed)

(1) Compressed files: Compress file (generates FILE.Z compressed files and deletes source files)

(2) Options:

-c:compress-c file > file.z (Generate compressed files while preserving source files, redirect compressed files to save them)

-D: Uncompressed (equivalent to uncompress)

(3)-#: Specify compression ratio, default is 6 (can fetch range of 1-9)

Note: The above four kinds of compression methods only support text file compression, not support directory file compression.

5. Archive (package multiple files together)

Description: The purpose of the archive is to back up the files, so the archive does not delete the source files. The archive file is compressed and decompressed using the tar command.

Tar command:

(1) syntax format: tar options file

(2) Create an archive (to package the file)

-c-f/path/to/somefile.tar FILE ...

-C: Create an archive

-f/path/to/somefile.tar: The file to be created (when executing the command line, the-F must be placed after the-C, because the parameter followed by-F)

FILE ... : Files that need to be archived

Eg: #tar-cf/tmp/mylog.tar fs Fsfs FSFSF

(3) Expand the archive (separate the packaged files)

-XF file. Tar (default to current directory open)

-X: Expand Archive

-f file. Tar-c/path/to/somedir: Separates the packaged files and opens the compressed file to a path in the directory file via-C .

(4) Archiving and compression (compared with the first archive and then compress, this can be done in one step)

Option:-Z (gzip) (-Z Effect: Tag using which compression decompression tool)

-zcf/path/to/somefile.tar.gz FILE ...

Unzip the expanded archive:-zxf (or-XF because the. GZ in the parameter automatically identifies which decompression tool to use, without the-Z-line) path file. tar.gz

-J:BZIP2 (indicates which compression tool to use)

-jcf

-JXF (or-XF)

-j:xz

-jcf

-JXF (or XF)

Linux compression decompression tools-Daily learning

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.