概念:file命令能够查看一个文件或者目录属于什么的。 [root@localhost tmp]# file 1.txt.gz #查看这个文件是什么类别的 1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Sat Apr 14 14:43:49 2018
概念:在Windows下咱们接触最多的压缩文件 .rar 格式; 但在Linux下,不能识别这种格式,他有本身独特的压缩工具; 但.zip格式的文件在Windows和Linux下均可以使用; Windows常见的压缩文件:.rar 、.zip 、.7Z Linux经常使用的压缩文件:.zip 、.gz 、.bz2 、.xz 、.tar 、.gz 、 .tar 、.bz2 、.tar.xz 压缩文件,不只能节省磁盘空间,并且在传输能节省网络带宽。
命令格式: gzip [-d#] filename,其中#为1-9的数字 -d 该参数在解压缩时使用 -# 表示压缩等级,1为最差,9为最好,6为默认
建立一个目录网络
[root@localhost tmp]# mkdir d6z
[root@localhost tmp]# cd d6z/工具
find搜索一个大的文件出来spa
[root@localhost d6z]# find /etc/ -type f -name "*conf".net
find 搜索,/etc/目录下,-type f 指定搜索类型为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/lvm/lvm.conf
/etc/lvm/lvmlocal.conf3d
把搜索的这些文件的内容,输出到一个文件里code
[root@localhost d6z]# find /etc/ -type f -name "*conf" -exec cat {} >> 1.txt \;blog
find 搜索,/etc/目录下,-type f 指定搜索类型为f普通文档的文件,-name "*conf"查找名字觉得conf结尾的全部文件,-exec推进后面的命令,cat {} 针对全部文件挨个查看 {}表示列出来的文件,>> 追加到 1.txt文件里 \;
[root@localhost d6z]# find /etc/ -type f -name "*conf" -exec cat {} >> 1.txt \;
[root@localhost d6z]# !du
du -sh 1.txt #查看这个文件的大小
2.2M 1.txt
[root@localhost d6z]# wc -l 1.txt #查看这个文件的行数总共有多少
37765 1.txtip
接下来用gzip压缩它
[root@localhost d6z]# gzip 1.txt
[root@localhost d6z]# ls
1.txt.gz
[root@localhost d6z]# du -sh 1.txt.gz #再来查看这个文件的大小
372K 1.txt.gz文档
解压gzip包get
[root@localhost d6z]# gzip -d 1.txt.gz #选项-d在解压缩时使用
[root@localhost d6z]# ls #查看文件
1.txt
[root@localhost d6z]# du -sh 1.txt #查看大小,这里跟以前的不同,是由于这个文件里原本就有虚空间。
1.5M 1.txt
查看压缩文件的信息,用file
[root@localhost d6z]# file 1.txt.gz
1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Sat Apr 14 14:14:22 2018
查看压缩文件的内容,用zcat
[root@localhost d6z]# zcat 1.txt.gz
压缩时候,指定到一个目录,而且不让这个原文件消失
[root@localhost d6z]# gzip -d 1.txt.gz #先给以前压缩的文件解压
gzip: 1.txt.gz: No such file or directory
[root@localhost d6z]# gzip -c 1.txt > /tmp/1.txt.gzgzip解压缩 -c指定 1.txt文件,>重镜像到,/tmp/1.txt.gz
[root@localhost d6z]# ls
1.txt
[root@localhost d6z]# ls /tmp/1.txt.gz
/tmp/1.txt.gz
解压时,不删除,指定一个地方
[root@localhost d6z]# gzip -d -c /tmp/1.txt.gz > /tmp/d6z/2.txt
概念:操做与gzip同样,只是比gzip压缩的更狠一点,占用的cpu越多。 bzip2命令格式为: bzip2 [-dz] filename 参数选项只有 -d(解压缩) -z(压缩) 压缩级别分别是1~9,默认是9级。
yum安装源码包bzip2
[root@localhost d6z]# yum install -y bzip2
概念:操做跟gzip和bizp2是同样的。 这个比gzip和dzip2都狠。 参数-d (解压缩) -z(压缩)
具体示例以下:
[root@localhost d6z]# xz 1.txt #压缩1.txt文件
[root@localhost d6z]# ls #查看
1.txt.xz 2.txt
[root@localhost d6z]# xz -d 1.txt.xz #解压缩1.txt.xz文件
[root@localhost d6z]# ls #查看
1.txt 2.txt
[root@localhost d6z]# xz -c 1.txt > /tmp/3.txt.xz #重镜像1.txt文件到/tmp目录下新生成3.txt.xz,保留原文件
[root@localhost d6z]# ls /tmp/
1.txt.gz systemd-private-d4565e90fd384c749a36d51b19e3e377-chronyd.service-91Lo0Y
2.txt systemd-private-d4565e90fd384c749a36d51b19e3e377-vgauthd.service-XKotz4
3.txt.xz systemd-private-d4565e90fd384c749a36d51b19e3e377-vmtoolsd.service-NZwSqa
d6z yum.log
ks-script-5ToQJK
[root@localhost d6z]# xz -d -c /tmp/3.txt.xz >3.txt
[root@localhost d6z]# ls
1.txt 2.txt 3.txt