[root@localhost ~]# cd /tmp/ [root@localhost tmp]# ls 11.sh han.111 23.sh fstab [root@localhost tmp]# mkdir d6z
[root@localhost tmp]# cd d6z [root@localhost d6z]# find /etc/ -type f -name "*conf" 查找全部文件中,名字以conf结尾的文件 /etc/resolv.conf /etc/pki/ca-trust/ca-legacy.conf /etc/yum/pluginconf.d/fastestmirror.conf /etc/yum/pluginconf.d/langpacks.conf /etc/yum/protected.d/systemd.conf /etc/yum/version-groups.conf /etc/rdma/mlx4.conf /etc/rdma/rdma.conf
[root@localhost d6z]# find /etc/ -type f -name "*conf" -exec cat {} >> 1.txt \; [root@localhost d6z]#
[root@localhost d6z]# ls 1.txt [root@localhost d6z]# du -sh 1.txt 3.2M 1.txt
这里屡次追加会看到文件,du -sh 1.txt查看的文件数值不一样,但在屡次查看,文件大小会恢复正常。(跳转数值较大比,是由于这个文件自己存在不少空隙,最后在压缩并解压后,会发现大小会有不一样)linux
[root@localhost d6z]# gzip 1.txt [root@localhost d6z]# ls 1.txt.gz会看到源文件消失了,变成了.gz的压缩文件 1.查看压缩文件大小
[root@localhost d6z]# du -sh 1.txt.gz 332K 1.txt.gz
[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
. gzip -n(数字) 文件名 //指定压缩级别windows
[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平台,最后一次的更改时间,压缩的级别less
[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]# 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)spa
[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
查看的时候,需注意压缩文件是否为空,若为空,则看不到什么文件.net
[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