1 压缩打包介绍
linux常见打包格式 .zip .gz .bz2 .xz .tar.gz .tar.bz2 .tar.xz
2 gzip 压缩工具---不支持压缩目录的
XZ 压缩工具--同样也不可以压缩目录:
语法: gzip [-d#] filename 其中#范围1-9,默认6
[root@node69 ~]# cd /tmp/
[root@node69 tmp]# mkdir d6z
[root@node69 tmp]# cd d6z/
[root@node69 d6z]# find /etc/ -type f -name "*conf" -exec cat {} >>1.txt \;
[root@node69 d6z]# ls
1.txt
[root@node69 d6z]# du -sh 1.txt
636K 1.txt
[root@node69 d6z]# find /etc/ -type f -name "*conf" -exec cat {} >>1.txt \;
[root@node69 d6z]# find /etc/ -type f -name "*conf" -exec cat {} >>1.txt \;
[root@node69 d6z]# du -sh 1.txt
2.6M 1.txt
[root@node69 d6z]# wc -l 1.txt
55383 1.txt
[root@node69 d6z]# gzip 1.txt
[root@node69 d6z]# ls
1.txt.gz
[root@node69 d6z]# du -sh 1.txt.gz
496K 1.txt.gz
[root@node69 d6z]# gzip -d 1.txt.gz
[root@node69 d6z]# ls
1.txt
[root@node69 d6z]# du -sh 1.txt
1.9M 1.txt
gzip -c 文件名 > 另存文件名:表示压缩文件后而不删除源文件,把压缩文件定向到指定目录和名称[root@node69 d6z]# gzip -c 1.txt > /tmp/1.txt.gz
[root@node69 d6z]# ls
1.txt
[root@node69 d6z]# ls /tmp/1.txt.gz
/tmp/1.txt.gz
[root@node69 d6z]# file !$
file /tmp/1.txt.gz
/tmp/1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Fri Nov 10 09:23:59 2017
[root@node69 d6z]# gzip -d -c /tmp/1.txt.gz > /tmp/d6z/2.txt
[root@node69 d6z]# ls
1.txt 2.txt
[root@node69 d6z]# wc -l 1.txt 2.txt
55383 1.txt
55383 2.txt
110766 总用量
[root@node69 d6z]# du -sh *.txt
1.9M 1.txt
1.9M 2.txt
bzip2压缩工具--同样也不可以压缩目录:
默认没有安装,需要安装# yum install -y bzip2
[root@node69 d6z]# bzip2 1.txt
[root@node69 d6z]# ls
1.txt.bz2 2.txt
[root@node69 d6z]# du -sh 1.txt.bz2
360K 1.txt.bz2
[root@node69 d6z]# du -sh 2.txt
1.9M 2.txt
[root@node69 d6z]# bzip2 -d 1.txt.bz2
[root@node69 d6z]# bzip2 1.txt
[root@node69 d6z]# bunzip2 1.txt.bz2
[root@node69 d6z]# ls
1.txt 2.txt
XZ 压缩工具--同样也不可以压缩目录:
[root@node69 d6z]# xz 2.txt
[root@node69 d6z]# du -sh 2.txt.xz
144K 2.txt.xz
[root@node69 d6z]# xz -d 2.txt.xz
[root@node69 d6z]# xz 2.txt
[root@node69 d6z]# unxz 2.txt.xz
[root@node69 d6z]# ls
1.txt 2.txt