6.1 压缩打包介绍 6.2 gzip压缩工具 6.3 bzip2压缩工具 6.4 xz压缩工具 6.5 zip压缩工具 6.6 tar打包 6.7 打包并压缩 看下这个帖子: http://ask.apelearn.com/question/5435
[root@linux-01 ~]# ll
总用量 444
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]# gzip 1.txt 2.txt bb.log
[root@linux-01 ~]# ll
总用量 124
-rw-r--r--. 1 root root 107247 3月 26 22:26 1.txt.gz
-rw-r--r--. 1 root root 830 3月 26 22:31 2.txt.gz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 6116 3月 26 22:20 bb.log.gz
[root@linux-01 ~]#
[root@linux-01 ~]# gzip -c 1.txt > 1.txt.gz
[root@linux-01 ~]# ll
总用量 552
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 107247 3月 26 22:51 1.txt.gz
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]# gzip -1 -c 1.txt > 1.txt.gz
[root@linux-01 ~]# file 1.txt.gz # 用file可以查看文件信息
1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Tue Mar 26 22:26:08 2019, max speed
[root@linux-01 ~]# gzip -9 -c 1.txt > 1.2.txt.gz
[root@linux-01 ~]# file 1.2.txt.gz
1.2.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Tue Mar 26 22:26:08 2019, max compression
[root@linux-01 ~]# ll
总用量 124
-rw-r--r--. 1 root root 107247 3月 26 22:26 1.txt.gz
-rw-r--r--. 1 root root 830 3月 26 22:31 2.txt.gz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 6116 3月 26 22:20 bb.log.gz
[root@linux-01 ~]# gzip -d 1.txt.gz 2.txt.gz bb.log.gz
[root@linux-01 ~]# ll
总用量 444
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
[root@linux-01 ~]# gzip -d -c 3.txt.gz
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
xihaji:x:1000:1000::/home/xihaji:/bin/bash
xihaji2:x:1001:1001::/home/xihaji2:/bin/bash
readonly:x:1002:1002::/home/readonly:/bin/bash
[root@linux-01 ~]# gzip -d -c 3.txt.gz > 3.txt
[root@linux-01 ~]# ll
总用量 560
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 107247 3月 26 22:51 1.txt.gz
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 933 3月 26 23:18 3.txt
-rw-r--r--. 1 root root 413 3月 26 22:54 3.txt.gz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]# cat /etc/passwd > 3.txt
[root@linux-01 ~]# gzip -c 3.txt > 3.txt.gz
[root@linux-01 ~]# zcat 3.txt.gz
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
xihaji:x:1000:1000::/home/xihaji:/bin/bash
xihaji2:x:1001:1001::/home/xihaji2:/bin/bash
readonly:x:1002:1002::/home/readonly:/bin/bash
bzip2 系统最小化安装没有安装,需要安装下。
[root@linux-01 ~]# yum install -y bzip2-1.0.6-13.el7.x86_64
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: ap.stykers.moe
* extras: mirrors.zju.edu.cn
* updates: mirrors.njupt.edu.cn
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
updates/7/x86_64/primary_db | 3.4 MB 00:00:01
正在解决依赖关系
--> 正在检查事务
---> 软件包 bzip2.x86_64.0.1.0.6-13.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=====================================================================================================================================
Package 架构 版本 源 大小
=====================================================================================================================================
正在安装:
bzip2 x86_64 1.0.6-13.el7 base 52 k
事务概要
=====================================================================================================================================
安装 1 软件包
总下载量:52 k
安装大小:82 k
Downloading packages:
bzip2-1.0.6-13.el7.x86_64.rpm | 52 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : bzip2-1.0.6-13.el7.x86_64 1/1
验证中 : bzip2-1.0.6-13.el7.x86_64 1/1
已安装:
bzip2.x86_64 0:1.0.6-13.el7
完毕!
[root@linux-01 ~]# bzip2 3.txt
[root@linux-01 ~]# ll
总用量 448
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 453 3月 26 23:18 3.txt.bz2
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]# bzip2 -c 3.txt > 3.txt.bz2
[root@linux-01 ~]# ll
总用量 452
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 933 3月 26 23:18 3.txt
-rw-r--r--. 1 root root 453 3月 27 00:36 3.txt.bz2
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
bzip2和gzip的压缩级别类似,也是有9个,1-9,默认压缩级别是9.
[root@linux-01 ~]# bzip2 -1 3.txt
[root@linux-01 ~]# file 3.txt.bz2
3.txt.bz2: bzip2 compressed data, block size = 100k
[root@linux-01 ~]# bzip2 -d 3.txt.bz2 # 解压文件
[root@linux-01 ~]# bzip2 -9 3.txt
[root@linux-01 ~]# file 3.txt.bz2
3.txt.bz2: bzip2 compressed data, block size = 900k
[root@linux-01 ~]# bzip2 -d 3.txt.bz2
[root@linux-01 ~]# ll
总用量 448
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 933 3月 26 23:18 3.txt
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
[root@linux-01 ~]# bzip2 -c -d 3.txt.bz2 > 3.txt
[root@linux-01 ~]# ll
总用量 452
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 933 3月 27 00:56 3.txt
-rw-r--r--. 1 root root 453 3月 26 23:18 3.txt.bz2
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]# bzcat 3.txt.bz2
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
xihaji:x:1000:1000::/home/xihaji:/bin/bash
xihaji2:x:1001:1001::/home/xihaji2:/bin/bash
readonly:x:1002:1002::/home/readonly:/bin/bash
[root@linux-01 ~]# xz 3.txt
[root@linux-01 ~]# ll
总用量 448
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
[root@linux-01 ~]# xz -c 2.txt > 2.txt.xz
[root@linux-01 ~]# ll
总用量 452
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
xz与bzip2和gzip类似, -0 到 -9调节压缩率。如果不设置,默认压缩等级是6.
[root@linux-01 ~]# xz -1 1.txt
[root@linux-01 ~]# ll
总用量 88
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 52372 3月 26 22:26 1.txt.xz
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]# xz -d 1.txt.xz
[root@linux-01 ~]# ll
总用量 452
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]# xz -d -c 3.txt.xz >3.txt
[root@linux-01 ~]# ll
总用量 456
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 933 3月 27 02:58 3.txt
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]# xzcat 3.txt.xz
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
xihaji:x:1000:1000::/home/xihaji:/bin/bash
xihaji2:x:1001:1001::/home/xihaji2:/bin/bash
readonly:x:1002:1002::/home/readonly:/bin/bash
[root@linux-01 ~]#
[root@linux-01 ~]# yum install -y zip
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: ap.stykers.moe
* extras: mirrors.zju.edu.cn
* updates: mirrors.njupt.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 zip.x86_64.0.3.0-11.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=====================================================================================================================================
Package 架构 版本 源 大小
=====================================================================================================================================
正在安装:
zip x86_64 3.0-11.el7 base 260 k
事务概要
=====================================================================================================================================
安装 1 软件包
总下载量:260 k
安装大小:796 k
Downloading packages:
zip-3.0-11.el7.x86_64.rpm | 260 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : zip-3.0-11.el7.x86_64 1/1
验证中 : zip-3.0-11.el7.x86_64 1/1
已安装:
zip.x86_64 0:3.0-11.el7
完毕!
[root@linux-01 ~]# zip 2.txt.zip 2.txt
adding: 2.txt (deflated 74%)
[root@linux-01 ~]# ll
总用量 568
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 108925 3月 27 03:12 1.txt.zip
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 966 3月 27 03:15 2.txt.zip
-rw-r--r--. 1 root root 933 3月 27 02:58 3.txt
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
[root@linux-01 ~]# zip 1.txt.zip 1.txt 2.txt 3.txt 111/
adding: 1.txt (deflated 75%)
adding: 2.txt (deflated 74%)
adding: 3.txt (deflated 58%)
adding: 111/ (stored 0%)
[root@linux-01 ~]# ll
总用量 564
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 108925 3月 27 03:12 1.txt.zip
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 933 3月 27 02:58 3.txt
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
[root@linux-01 ~]# yum install -y unzip
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: ap.stykers.moe
* extras: mirrors.zju.edu.cn
* updates: mirrors.njupt.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 unzip.x86_64.0.6.0-19.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=====================================================================================================================================
Package 架构 版本 源 大小
=====================================================================================================================================
正在安装:
unzip x86_64 6.0-19.el7 base 170 k
事务概要
=====================================================================================================================================
安装 1 软件包
总下载量:170 k
安装大小:365 k
Downloading packages:
unzip-6.0-19.el7.x86_64.rpm | 170 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : unzip-6.0-19.el7.x86_64 1/1
验证中 : unzip-6.0-19.el7.x86_64 1/1
已安装:
unzip.x86_64 0:6.0-19.el7
完毕!
[root@linux-01 ~]#
[root@linux-01 ~]# unzip 1.txt.zip
Archive: 1.txt.zip
replace 1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: 1.txt
replace 2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: 2.txt
replace 3.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: 3.txt
[root@linux-01 ~]# unzip 1.txt.zip -d /root/test/
Archive: 1.txt.zip
inflating: /root/test/1.txt
inflating: /root/test/2.txt
inflating: /root/test/3.txt
creating: /root/test/111/
[root@linux-01 ~]# ll test/
总用量 424
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 933 3月 27 02:58 3.txt
[root@linux-01 ~]#
[root@linux-01 ~]# unzip -l 1.txt.zip
Archive: 1.txt.zip
Length Date Time Name
--------- ---------- ----- ----
425886 03-26-2019 22:26 1.txt
3147 03-26-2019 22:31 2.txt
933 03-27-2019 02:58 3.txt
0 03-27-2019 02:47 111/
--------- -------
429966 4 files
[root@linux-01 ~]#
## 基本格式:tar [Options] file_archive //注意tar的第一参数必须为命令选项,即不能直接接待处理文件
- 常用命令参数:
-c #创建一个新的打包文件(archive)
-x # 对打包文件(archive)进行解压操作
-t # 查看打包文件(archive)的内容,主要是构成打包文件(archive)的文件名
-z # 使用gzip进行压缩/解压,一般使用.tar.gz后缀
-j # 使用bzip2进行压缩/解压,一般使用.tar.bz2后缀
-f # 指定tar指令使用的文件,若没有压缩操作,则以.tar作为后缀
-v # 详细显示正在处理的文件名
-C Dir # 将解压文件放置在 -C 指定的目录下
-p(小写) # 保留文件的权限和属性,在备份文件时较有用
-P(大写) # 保留原文件的绝对路径,即不会拿掉文件路径开始的根目录,则在还原时会覆盖对应路径上的内容
--exclude=file # 排除不进行打包的文件
[root@linux-01 ~]# tar -cvf 111.tar 111
111/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
111/test/
[root@linux-01 ~]# ll
总用量 564
drwxr-xr-x. 3 root root 106 3月 28 03:08 111
-rw-r--r--. 1 root root 552960 3月 28 03:11 111.tar
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
drwxr-xr-x. 3 root root 56 3月 27 03:27 test
[root@linux-01 ~]#
## 打包文件排除某些文件 ##
[root@linux-01 ~]# tar -cvf 111.tar 111/ --exclude 1.txt --exclude 2.txt
111/
111/test/
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
[root@linux-01 ~]#
[root@linux-01 ~]# tar -xvf 111.tar
111/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
111/test/
[root@linux-01 ~]# tar -tf 111.tar
111/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
111/test/
[root@linux-01 ~]# tar -czvf 111.tar.gz 111/
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
[root@linux-01 ~]# ll
总用量 360
drwxr-xr-x. 3 root root 106 3月 28 03:08 111
-rw-r--r--. 1 root root 122880 3月 28 03:20 111.tar
-rw-r--r--. 1 root root 221138 3月 28 03:23 111.tar.gz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
drwxr-xr-x. 3 root root 56 3月 27 03:27 test
[root@linux-01 ~]# du -sh 111.tar.gz
216K 111.tar.gz
[root@linux-01 ~]#
[root@linux-01 ~]# tar -cjvf 111.tar.bz2 111/
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
[root@linux-01 ~]# du -sh 111.tar.bz2
176K 111.tar.bz2
[root@linux-01 ~]#
[root@linux-01 ~]# tar -cJvf 111.tar.xz 111/
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
[root@linux-01 ~]# du -sh 111.tar.xz
156K 111.tar.xz
[root@linux-01 222]# tar -zxvf 111.tar.gz
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
[root@linux-01 222]# tar -jxvf 111.tar.bz2
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
[root@linux-01 222]# tar -Jxvf 111.tar.xz
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
命令 | 文件格式 | 压缩文件(源文件不保留) | 压缩文件(源文件保留) | 默认压缩级别 | 解压 (源文件不保留) | 解压 (源文件保留) | 查看压缩文件 |
---|---|---|---|---|---|---|---|
gzip | file.gz | gzip file.gz | gzip -c file > file.xz | 6 | gzip -d file.gz | gzip -d -c file.gz >file | zcat file.gz |
bzip2 | file.bz2 | bzip2 file.bz2 | bzip2 -c file > file.xz | 9 | bzip2 -d file.bz2 | bzip2 -d -c file.bz2 >file | bzcat file.bz2 |
xz | file.xz | xz file.xz | xz -c file > file.xz | 6 | xz -d file.xz | xz -d -c file.xz >file | zxcat file.xz |