Compression tools are: Zip, gzip, bzip2, XZ
Archive tools are: tar, cpio
One, the compression tool
Zip
1. Compression
[Email protected] tmp]# zip messages.gz messages Adding:messages (deflated 86%) [[email protected] tmp]# Ls-ltotal 420 -RW-------1 root root 376011 mar 23:14 messages-rw-r--r--1 root root 52512 Mar-23:15 messages.gz
2. Decompression
[Email protected] tmp]# Unzip messages.gz
Zip can also compress the directory but must use the file name to pass all the files in its directory, by default it will not pack all the files in the directory.
[[email protected] tmp]# zip etc.gz/etc \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ adding:etc/(stored 0) [[email protected] tmp]# zip etc.gz/etc/ * \ \ Correct compression method must use the file name of all the files in the directory
Note : Although you use a wildcard to specify all the files in the directory, the files in the subdirectory directory are still not packed and compressed
Gzip
Common options
-D Decompression
-C Send the compressed result to standard output, you can use redirection to save it as a compressed file, thus preserving the original file
1, compression, will not retain the original file after compression.
[[email protected] tmp]# Ls-lh messages-rw-------1 root root 368K Mar-23:14 messages[[email protected] tmp]# gzip me ssages [[email protected] tmp]# Ls-lh messages.gz-rw-------1 root root 52K Mar 23:14 messages.gz
2, decompression, will not retain the original file after decompression.
# Gunzip Messages.gz
Or
# gzip-d Messages.gz
3, do not press the compressed package to view the contents directly
# Zcat Messages.gz
4, the default compression will not retain its original files, if necessary, you can use the following methods.
# GZIP-C Messages > Messages.gz
bzip2, bunzip2 = bzip2-d, Bzcat
Suffix:. bz2
1. Compression
[Email protected] tmp]# bzip2 messages [[email protected] tmp]# ls-ltotal 24-rw-r--r--1 root root 22094 Mar 23:38 me ssages.bz2
2. Decompression
# bzip2-d MESSAGES.BZ2
Or
# BUNZIP2 MESSAGES.BZ2
XZ, Unxz = xz-d, Xzcat
Suffix:. xz
1. Compression
[Email protected] tmp]# XZ messages [[email protected] tmp]# ls-ltotal 20-rw-r--r--1 root root 17508 Mar 23:38 Messa Ges.xz
2. Decompression
# xz-d MESSAGES.XZ
Or
# UNXZ MESSAGES.XZ
Second, the Archive tool
Tar
tar [options]-f file.tar File1 ...
Options
-C: Create an archive
-X: Expand Archive
-T: Directly view archived files without expanding
-C: Specify a compressed directory
-Z: Call gzip compression, suffix GZ
-j: Call bzip2 tool compression with suffix bz2
-j: Call XZ tool compression, suffix XZ
1. Package only for/etc directory
# tar CF Etc.tar etc
2, Packaging etc directory and using the Gzip tool for compression
[[email protected] tmp]# TAR-ZCF etc.tar.gz etc[[email protected] tmp]# lsetc etc.tar.gz messages
3, decompression, you can not specify which compression tool to use.
# Tar XF etc.tar.gz
4, specify to extract to the specified directory
[[Email protected] tmp]# tar XF etc.tar.gz-c/tmp/mem[[email protected] tmp]# ls/tmp/memetc
This article is from "Rookie Diary" blog, please make sure to keep this source http://zkxfoo.blog.51cto.com/1605971/1749359
Linux each compression tool