[root@localhost d6z]# find /etc/ -type f -name "*conf" -exec cat {} >> 1.txt \; [root@localhost d6z]#
这里多次追加会看到文件,du -sh 1.txt查看的文件数值不同,但在多次查看,文件大小会恢复正常。(跳转数值较大比,是因为这个文件本身存在很多空隙,最后在压缩并解压后,会发现大小会有不同)
[root[@localhost](https://my.oschina.net/u/570656) d6z]# gzip -d 1.txt.gz
[root[@localhost](https://my.oschina.net/u/570656) d6z]# ls
1.txt
[root[@localhost](https://my.oschina.net/u/570656) d6z]# du -sh 1.txt
1.3M 1.txt
[root@localhost d6z]# gunzip 1.txt.gz
[root@localhost d6z]# ls
1.txt
[root@localhost d6z]# du -sh 1.txt
1.3M 1.txt
[root@localhost d6z]# file 1.txt.gz
1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Thu Nov 9 14:23:33 2017, max compression
这里会看到这是一个gzip的压缩数据,名称是1.txt,基于Unix平台,最后一次的更改时间,压缩的级别
[root@localhost d6z]# gzip -c 1.txt > /tmp/1.txt.gz
[root@localhost d6z]# ls /tmp/1.txt.gz
/tmp/1.txt.gz
[root@localhost d6z]# gunzip -c /tmp/1.txt.gz >/tmp/d6z/2.txt
[root@localhost d6z]# ls
1.txt 2.txt
[root@localhost d6z]# gzip -c -d /tmp/1.txt.gz >/tmp/d6z/2.txt
[root@localhost d6z]# ls
1.txt 2.txt
1.txt和2.txt这两个文件大小相同(du -sh 1.txt 2.txt),行数形同(wc -l 1.txt 2.txt)
[root@hf-01 d6z]# du -sh 1.txt
2.0M 1.txt
[root@hf-01 d6z]# bzip2 1.txt
[root@hf-01 d6z]# ls
1.txt.bz2
[root@hf-01 d6z]# du -sh 1.txt.bz2
168K 1.txt.bz2
[root@hf-01 d6z]# bzip2 -d 1.txt.bz2
[root@hf-01 d6z]# ls
1.txt
[root@hf-01 d6z]# du -sh 1.txt
1.5M 1.txt
[root@hf-01 d6z]# bunzip2 1.txt.bz2
[root@hf-01 d6z]# ls
1.txt
[root@hf-01 d6z]# bzip2 -c 1.txt > /tmp/2.txt.bz2
[root@hf-01 d6z]# du -sh /tmp/2.txt.bz2
168K /tmp/2.txt.bz2
[root@hf-01 d6z]# bzip2 -d -c /tmp/2.txt.bz2 > 4.txt
[root@hf-01 d6z]# ls
1.txt 4.txt
[root@hf-01 d6z]# du -sh 4.txt
1.5M 4.txt
[root@hf-01 d6z]# bunzip2 1.txt.bz2 > 5.txt
[root@hf-01 d6z]# ls
1.txt 4.txt 5.txt
[root@hf-01 d6z]# file 1.txt.bz2
1.txt.bz2: bzip2 compressed data, block size = 900k
[root@hf-01 d6z]# bzcat 1.txt.bz2
查看的时候,需注意压缩文件是否为空,若为空,则看不到什么文件
[root@hf-01 d6z]# xz 1.txt
[root@hf-01 d6z]# ls
1.txt.xz 4.txt 5.txt
[root@hf-01 d6z]# du -sh 1.txt.xz
60K 1.txt.xz
[root@hf-01 d6z]# xz -d 1.txt.xz
[root@hf-01 d6z]# ls
1.txt 4.txt 5.txt
[root@hf-01 d6z]# du -sh 1.txt
1.5M 1.txt
[root@hf-01 d6z]# unxz 1.txt.xz
[root@hf-01 d6z]# ls
1.txt 4.txt 5.txt
[root@hf-01 d6z]# xz -c 1.txt > /tmp/ha.txt.xz
[root@hf-01 d6z]# du -sh /tmp/ha.txt.xz
60K /tmp/ha.txt.xz
[root@hf-01 d6z]# unxz -c /tmp/ha.txt.xz > ./8.txt
[root@hf-01 d6z]# ls
1.txt 4.txt 5.txt 8.txt
[root@hf-01 d6z]# du -sh 8.txt
1.5M 8.txt