linux压缩和打包工具gzip_bzip2_xz_zip_tar

发布时间:2024-03-17
系统运维
gizp:
*gzip工具不能压缩目录,只能压缩文件
压缩:gzip filename
[root@localhost test01]# ll -h * #查看压缩前all.txt文件大小-rw-r--r-- 1 root root 4.2m 9月 7 13:44 all.txt[root@localhost test01]# gzip all.txt #压缩all.txt文件[root@localhost test01]# ll -h * #查看压缩后all.txt文件大小-rw-r--r-- 1 root root 1.2m 9月 7 13:44 all.txt.gz解压:gzip -d filename
[root@localhost test01]# lsall.txt.gz[root@localhost test01]# gzip -d all.txt.gz [root@localhost test01]# lsall.txt解压:gunzip -d filename
[root@localhost test01]# lsall.txt.gz[root@localhost test01]# gunzip -d all.txt.gz [root@localhost test01]# lsall.txt指定压缩率:gzip -n filename (n的范围:1-9,压缩等级9压缩率最高,压缩速度也就最慢,对cup资源的消耗也就相对过高,压缩等级1压缩率最低,压缩速度也就最快,对cpu资源的消耗相对过低,默认等级为6)
[root@localhost test01]# gzip -9 all.txt[root@localhost test01]# file all.txt.gz #file查看文件最后一列压缩等级为最大压缩率all.txt.gz: gzip compressed data, was all.txt, from unix, last modified: sat sep 7 13:44:13 2019, max compression查看压缩文件内容:(在不解压的情况下查看压缩文件内容使用zcat命令)
[root@localhost test01]# zcat all.txt.gz -c 参数:在压缩或解压时保留源文件
[root@localhost test01]# gzip -c all.txt > all.txt.gz[root@localhost test01]# lsall.txt all.txt.gz[root@localhost test01]# gzip -d -c all.txt.gz > all2.txt[root@localhost test01]# lsall2.txt all.txt all.txt.gzbzip2:
*与gzip类似,不能压缩目录,只能压缩文件,压缩率比gzip高
安装bzip2工具:
[root@localhost test01]# yum -y install bzip2压缩:bzip2 filename
解压:bizp2 -d filename 或 bunzip2 -d filename
查看压缩文件内容:bzcat filename
*与gzip一样可以指定压缩率,但bzip2默认压缩等级为9,同样可以使用-c参数
xz:
与gzip、bzip2类似,不能压缩目录,只能压缩文件,压缩率比gzip、bzip2高*
压缩:xz filename
解压:xz -d filename 或 unxz -d filename
查看压缩文件内容:xzcat filename
与gzip、bzip一样可以指定压缩率,默认压缩等级最高,同样可以使用-c参数
gzip、bzip2、xz在解压时使用-c参数不仅可以保留源文件,还可以重命名解压文件*
zip:
*zip可以压缩目录和文件,在解压时可以指定解压路径,但不能重命名解压内容
安装:
[root@localhost ~]# yum -y install zip压缩文件:zip 压缩文件名 源文件名 (源文件可以是多个文件)
[root@localhost test01]# lsfiletest.txt test02 test.sh[root@localhost test01]# zip abc.zip filetest.txt test.sh adding: filetest.txt (deflated 85%) adding: test.sh (deflated 79%)[root@localhost test01]# ls #将filetest.txt test.sh两个文件添加到压缩文件abc.zipabc.zip filetest.txt test02 test.sh压缩目录:zip -r 压缩文件名 源文件名 (源文件可以是多个目录和文件)
[root@localhost test01]# lsabc.zip filetest.txt test02 test.sh[root@localhost test01]# zip -r linuxtest.zip test02/ filetest.txt adding: test02/ (stored 0%) adding: test02/all.txt (deflated 71%) adding: filetest.txt (deflated 85%)[root@localhost test01]# lsabc.zip filetest.txt linuxtest.zip test02 test.sh*zip压缩或解压文件或目录后,会自动保留源文件
解压:unzip filename
[root@localhost test01]# lsabc.zip filetest.txt linuxtest.zip test02 test.sh[root@localhost test01]# rm -rf filetest.txt test.sh [root@localhost test01]# lsabc.zip linuxtest.zip test02[root@localhost test01]# unzip abc.zip archive: abc.zip inflating: filetest.txt inflating: test.sh [root@localhost test01]# lsabc.zip filetest.txt linuxtest.zip test02 test.sh将压缩文件中的内容解压到指定目录: unzip filename -d 目标目录路径
[root@localhost test01]# lsabc.zip filetest.txt linuxtest.zip test02 test.sh[root@localhost test01]# unzip linuxtest.zip -d /root/mytest/archive: linuxtest.zip creating: /root/mytest/test02/ inflating: /root/mytest/test02/all.txt inflating: /root/mytest/filetest.txt [root@localhost test01]# ls /root/mytest/filetest.txt test02查看压缩文件中的文件列表: unzip -l filename
*与gzip、bzip2、xz不同,unzip只能查看文件列表,不能查看文件中的内容
[root@localhost test01]# unzip -l linuxtest.zip archive: linuxtest.zip length date time name--------- ---------- ----- ---- 0 09-07-2019 15:18 test02/ 4340076 09-07-2019 13:44 test02/all.txt 2943 09-07-2019 15:26 filetest.txt--------- ------- 4343019 3 filestar:
*tar工具将多个文件或目录打包到一个文件中(比如要压缩一个目录,里面有很多小文件,可以使用tar将该目录先打包成一个文件再压缩),增加传输速度,对文件大小改变不会太大,tar打包时可以同时打包多个目录加文件
打包:tar -cvf 打包文件名 源文件
[root@localhost test01]# lstest02 test.sh[root@localhost test01]# tar -cvf testfile.tar test02/ t
上一个:普洱茶的“渥黄”是怎么一回事
下一个:外地户口能在上海离婚吗

流量控制仪表和液位控制仪表的一般故障分析步骤
茶适合种植在哪
如何控制苗圃的病虫害使苗木安全越冬
选择电子元器件商城需要注意的几个细节分析
因正当防卫造成损害的需要承担责任吗
房产买卖过户需要缴纳的税费有哪些
湖北水厂消毒设备/湖北电法次氯酸钠发生器厂家
手机找回小米账户密码怎么办,手机忘了小米帐号密码怎么办
KPF法兰式平衡阀
法桐小苗霉斑病的预防办法