Packing , also an archive, which means that one or more files or directories are converted into a total directory file. Files do not become smaller, they may become larger, and some additional callout information may be added. This process, you can approximate the understanding that multiple files or directories in Windows are moved under a specified directory.
Compression: Is the process of combining one or more files, combined with a compression program, by compressing a program-specific algorithm to "encapsulate" it into a new file in a special format. This compression process is the same as the concept of compression inside the Windows system.
First of all, to say packing.
package by command tar, syntax format: tar "option" file | directory. the commonly used parameters are C, V, F.
C-create creation; V-verbose detailed; f-file Follow-up file name; X-extract Extract and decompress
Note: v can be omitted, there is a difference between this parameter band and without, suggest or bring
x unpack the tar file, basically not, usually unpacked and compressed after the file
[email protected] mnt]# LL
-rw-rw-r--. 1 root root 0 3 month 1222:56 py
drwxr-xr-x. 2 root root 4096 3 Month 4 17:28 test
[Email protected] mnt]# TAR-CVF Py.tar py
Py
[Email protected] mnt]# TAR-CF Test.tar test
[email protected] mnt]# LL
-rw-rw-r--. 1 root root 0 3 month 1222:56 py
-rw-r--r--. 1 root root 10240 3 month 22:59 Py.tar
drwxr-xr-x. 2 root root 4096 3 Month 417:28 Test
-rw-r--r--. 1 root root 10240 3 month 22:59 Test.tar
The following is the process of unpacking, and its related parameters are X
[email protected] opt]# LL
drwxr-xr-x. 2 root root 4096 3 Month 262015 RH
-rw-r--r--. 1 root root 10240 3 month 23:25 Rh.tar
[Email protected] opt]# MV RH Rh.bak
[Email protected] opt]# TAR-XVF Rh.tar
rh/
[email protected] opt]# LL
drwxr-xr-x. 2 root root 4096 3 Month 262015 RH
drwxr-xr-x. 2 root root 4096 3 month 262015 Rh.bak
-rw-r--r--. 1 root root 10240 3 month 23:25 Rh.tar
Second, let's talk about compression
Common compression programs are GZ, BZ2, XZ, the following examples illustrate
[email protected] mnt]# LL
-rw-r--r--. 1 root root 0 3 month 00:07 KK
-rw-r--r--. 1 root root 0 3 month 00:07 py
-rw-r--r--. 1 root root 0 3 Month 00:08 SEO
[Email protected] mnt]# gzip KK
[Email protected] mnt]# bzip2 py
[[email protected] mnt]# xz SEO
[email protected] mnt]# LL
-rw-r--r--. 1 root root 3 month 00:07 kk.gz
-rw-r--r--. 1 root root 3 month 00:07 py.bz2
-rw-r--r--. 1 root root 3 month 00:08 seo.xz
The above is the process of compressing each of the three commands separately, compared to the following, the only difference is that the original file is not retained after compression, and the following add some parameters, good retention of the original document.
gzip retains the original file by using the parameter-c similar redirect output. bzip2 and XZ plus parameter k to keep the original file. Specific as
[email protected] opt]# LL
-rw-r--r--. 1 root root 0 3 Month 00:02 book
-rw-r--r--. 1 root root 0 3 Moon 23:53 World
-rw-r--r--. 1 root root 0 3 month 00:02 Zhang
[Email protected] opt]# gzip-c book >book.gz
[Email protected] opt]# bzip2-k World
[Email protected] opt]# xz-k Zhang
[email protected] opt]# LL
-rw-r--r--. 1 root root 0 3 Month 1300:02 book
-rw-r--r--. 1 root root 3 month 00:05 book.gz
-rw-r--r--. 1 root root 0 3 Moon 1223:53 World
-rw-r--r--. 1 root root 3 month 23:53 world.bz2
-rw-r--r--. 1 root root 0 3 Moon 1300:02 Zhang
-rw-r--r--. 1 root root 3 month 00:02 zhang.xz
After the file is compressed, you can also view the contents of the compressed file by command, the command commands are zcat*.gz, Bzcat *.bz2, Xzcat *.xz
The following is an example of a file in GZ format
[email protected] mnt]# LL
-rw-r--r--. 1 root root 362 3 month 00:11 passwd
[Email protected] mnt]# gzip-c passwd >passwd.gz
[email protected] mnt]# LL
-rw-r--r--. 1 root root 362 3 month 00:11 passwd
-rw-r--r--. 1 root root 205 3 month 00:12 passwd.gz
[Email protected] mnt]# Zcat passwd.gz
Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/sbin/nologin
Postfix:x:89:89::/var/spool/postfix:/sbin/nologin
Zhangsan:x:503:504::/home/zhangsan:/bin/bash
Tomcat:x:496:493::/mydata:/sbin/nologin
Ddd:x:505:506::/home/ddd:/bin/bash
The unzip command described below
[email protected] opt]# LL
-rw-r--r--. 1 root root 3 month 00:05 book.gz
-rw-r--r--. 1 root root 3 month 23:53 world.bz2
-rw-r--r--. 1 root root 3 month 00:02 zhang.xz
[Email protected] opt]# gunzip book.gz
[Email protected] opt]# BUNZIP2 world.bz2
[Email protected] opt]# Unxz ZHANG.XZ
[email protected] opt]# LL
-rw-r--r--. 1 root root 0 3 Month 00:05 book
-rw-r--r--. 1 root root 0 3 Moon 23:53 World
-rw-r--r--. 1 root root 0 3 month 00:02 Zhang
About file compression, common GZ and bz2 format mostly, to practice and master
Finally, let's look at packing and compressing.
No explanation, direct description
[email protected] mnt]# LL
-rw-r--r--. 1 root root 362 3 month 1300:11 passwd
drwxr-xr-x. 2 root root 4096 3 Month 00:32 Test
[Email protected] mnt]# tar-zcvfpasswd.tar.gz passwd
passwd
[Email protected] mnt]# tar-jcvftest.tar.bz2 test
test/
[email protected] mnt]# LL
-rw-r--r--. 1 root root 362 3 month 1300:11 passwd
-rw-r--r--. 1 root root 289 3 month 1300:35 passwd.tar.gz
drwxr-xr-x. 2 root root 4096 3 Month 00:32 Test
-rw-r--r--. 1 root root 3 month 1300:35 test.tar.bz2
Here is the Unzip to procedure
[email protected] mnt]# LL
-rw-r--r--. 1 root root 289 3 month 00:35 passwd.tar.gz
-rw-r--r--. 1 root root 3 month 00:35 test.tar.bz2
[Email protected] mnt]# tar-zxvfpasswd.tar.gz
passwd
[Email protected] mnt]# tar-jxvftest.tar.bz2
test/
[email protected] mnt]# LL
-rw-r--r--. 1 root root 362 3 month 1300:11 passwd
-rw-r--r--. 1 root root 289 3 month 1300:35 passwd.tar.gz
drwxr-xr-x. 2 root root 4096 3 Month 00:32 Test
-rw-r--r--. 1 root root 3 month 1300:35 test.tar.bz2
Decompression by default is extracted to the current directory, you can use the parameter C to define the location after decompression. As shown in the following:
[email protected] opt]# LL
-rw-r--r--. 1 root root 0 3 month 00:02 Zhang
[Email protected] opt]# cd/mnt/
[email protected] mnt]# LL
-rw-r--r--. 1 root root 362 3 month 1300:11 passwd
-rw-r--r--. 1 root root 289 3 month 1300:35 passwd.tar.gz
drwxr-xr-x. 2 root root 4096 3 Month 00:32 Test
-rw-r--r--. 1 root root 3 month 1300:35 test.tar.bz2
[Email protected] mnt]# tar-zxvfpasswd.tar.gz-c/opt/
passwd
[Email protected] mnt]# ll/opt/
-rw-r--r--. 1 root root 362 3 month 00:11 passwd
-rw-r--r--. 1 root root 0 3 Moon 1300:02 Zhang
Finally, it is important to note the following:
1. Packaging and compression are two unused concepts and do not confuse each other.
2. compression can only be done for files and cannot be targeted to the directory.
3. can be packaged without compression, or can only be compressed not packaged, of course, we are generally both packaged and compressed.
4. Packaging and packaging compression syntax, can not be written in reverse order.
Specific: Command + parameters + package or package compressed file name + packaged files
This article is from the "Provoke Dust" blog, please make sure to keep this source http://liangww.blog.51cto.com/9468518/1757357
Small talk about packaging and compressing in LINUX