[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
[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平臺,最後一次的更改時間,壓縮的級別windows
[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)less
[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