linux壓縮和打包工具gzip_bzip2_xz_zip_tar

發(fā)布時(shí)間:2024-03-17
系統(tǒng)運(yùn)維
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,壓縮等級(jí)9壓縮率最高,壓縮速度也就最慢,對(duì)cup資源的消耗也就相對(duì)過高,壓縮等級(jí)1壓縮率最低,壓縮速度也就最快,對(duì)cpu資源的消耗相對(duì)過低,默認(rèn)等級(jí)為6)
[root@localhost test01]# gzip -9 all.txt[root@localhost test01]# file all.txt.gz #file查看文件最后一列壓縮等級(jí)為最大壓縮率all.txt.gz: gzip compressed data, was all.txt, from unix, last modified: sat sep 7 13:44:13 2019, max compression查看壓縮文件內(nèi)容:(在不解壓的情況下查看壓縮文件內(nèi)容使用zcat命令)
[root@localhost test01]# zcat all.txt.gz -c 參數(shù):在壓縮或解壓時(shí)保留源文件
[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
查看壓縮文件內(nèi)容:bzcat filename
*與gzip一樣可以指定壓縮率,但bzip2默認(rèn)壓縮等級(jí)為9,同樣可以使用-c參數(shù)
xz:
與gzip、bzip2類似,不能壓縮目錄,只能壓縮文件,壓縮率比gzip、bzip2高*
壓縮:xz filename
解壓:xz -d filename 或 unxz -d filename
查看壓縮文件內(nèi)容:xzcat filename
與gzip、bzip一樣可以指定壓縮率,默認(rèn)壓縮等級(jí)最高,同樣可以使用-c參數(shù)
gzip、bzip2、xz在解壓時(shí)使用-c參數(shù)不僅可以保留源文件,還可以重命名解壓文件*
zip:
*zip可以壓縮目錄和文件,在解壓時(shí)可以指定解壓路徑,但不能重命名解壓內(nèi)容
安裝:
[root@localhost ~]# yum -y install zip壓縮文件:zip 壓縮文件名 源文件名 (源文件可以是多個(gè)文件)
[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兩個(gè)文件添加到壓縮文件abc.zipabc.zip filetest.txt test02 test.sh壓縮目錄:zip -r 壓縮文件名 源文件名 (源文件可以是多個(gè)目錄和文件)
[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壓縮或解壓文件或目錄后,會(huì)自動(dòng)保留源文件
解壓: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將壓縮文件中的內(nèi)容解壓到指定目錄: unzip filename -d 目標(biāo)目錄路徑
[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只能查看文件列表,不能查看文件中的內(nèi)容
[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工具將多個(gè)文件或目錄打包到一個(gè)文件中(比如要壓縮一個(gè)目錄,里面有很多小文件,可以使用tar將該目錄先打包成一個(gè)文件再壓縮),增加傳輸速度,對(duì)文件大小改變不會(huì)太大,tar打包時(shí)可以同時(shí)打包多個(gè)目錄加文件
打包:tar -cvf 打包文件名 源文件
[root@localhost test01]# lstest02 test.sh[root@localhost test01]# tar -cvf testfile.tar test02/ t
上一個(gè):普洱茶的“渥黃”是怎么一回事
下一個(gè):外地戶口能在上海離婚嗎

流量控制儀表和液位控制儀表的一般故障分析步驟
茶適合種植在哪
如何控制苗圃的病蟲害使苗木安全越冬
選擇電子元器件商城需要注意的幾個(gè)細(xì)節(jié)分析
因正當(dāng)防衛(wèi)造成損害的需要承擔(dān)責(zé)任嗎
房產(chǎn)買賣過戶需要繳納的稅費(fèi)有哪些
湖北水廠消毒設(shè)備/湖北電法次氯酸鈉發(fā)生器廠家
手機(jī)找回小米賬戶密碼怎么辦,手機(jī)忘了小米帳號(hào)密碼怎么辦
KPF法蘭式平衡閥
法桐小苗霉斑病的預(yù)防辦法
十八禁 网站在线观看免费视频_2020av天堂网_一 级 黄 色 片免费网站_绝顶高潮合集Videos