tar and gzip and zip
一、tar:將多個檔案打包成一個檔案
1.打包指令:將dflist.txt dflist1.txt dflist2.txt三個檔案打包成一個[dflist.tar]檔案
bash-3.00# tar -cvf dflist.tar dflist.txt dflist1.txt dflist2.txt
2.解包指令:
bash-3.00# tar -xvf dflist.tar
3.查看tar檔的內的檔案
bash-3.00# tar -tf dflist.tar
================================================
二、gzip:將檔案or目錄做壓縮的動作
1.目錄內存有[dflist.tar] [dflist.txt] [dflist1.txt] [dflist2.txt] 四個檔案
bash-3.00# gzip -v df* ---->開頭df全部幫你做壓縮的動作
dflist.tar: 92.7% -- replaced with dflist.tar.gz
dflist.txt: 69.1% -- replaced with dflist.txt.gz
dflist1.txt: 69.1% -- replaced with dflist1.txt.gz
dflist2.txt: 69.1% -- replaced with dflist2.txt.gz
[dflist.tar.gz] [dflist.txt.gz] [dflist1.txt.gz] [dflist2.txt.gz]
(PS:如果要壓縮目錄 gzip -rv )
2.查看壓縮檔的內容:
bash-3.00# gzip -l dflist.txt.gz
compressed uncompressed ratio uncompressed_name
306 896 69.1% dflist.txt
3.檢視壓縮檔的完整度
bash-3.00# gzip -vt dflist.txt.gz
dflist.txt.gz: OK
4.解壓縮指令:
bash-3.00#gzip -dv df*
dflist.tar.gz: 92.7% -- replaced with dflist.tar
dflist.txt.gz: 69.1% -- replaced with dflist.txt
dflist1.txt.gz: 69.1% -- replaced with dflist1.txt
dflist2.txt.gz: 69.1% -- replaced with dflist2.txt
==================================================
三、打包+壓縮一個指令搞定的指令[zip]
1.bash-3.00# zip -v dflist.zip dflist.tar dflist.txt dflist1.txt dflist2.txt
adding: dflist.tar (in=5632) (out=410) (deflated 93%)
adding: dflist.txt (in=896) (out=277) (deflated 69%)
adding: dflist1.txt (in=896) (out=277) (deflated 69%)
adding: dflist2.txt (in=896) (out=277) (deflated 69%)
total bytes=8320, compressed=1241 -> 85% savings
目錄下會新增一個[dflist.zip]的檔案(如果要壓縮目錄加上 r 選項)
2.刪除壓縮檔內的某一個檔案
bash-3.00# zip -dv dflist.zip dflist.txt
zip info: local extra (21 bytes) != central extra (13 bytes): dflist.tar
zip info: local extra (21 bytes) != central extra (13 bytes): dflist.txt
zip info: local extra (21 bytes) != central extra (13 bytes): dflist1.txt
zip info: local extra (21 bytes) != central extra (13 bytes): dflist2.txt
deleting: dflist.txt
total bytes=7424, compressed=964 -> 87% savings
3.將檔案加入目前的壓縮檔內:
複製一份檔案加入
bash-3.00# zip -gv dflist.zip dflist3.txt
zip info: local extra (21 bytes) != central extra (13 bytes): dflist.tar
zip info: local extra (21 bytes) != central extra (13 bytes): dflist1.txt
zip info: local extra (21 bytes) != central extra (13 bytes): dflist2.txt
adding: dflist3.txt (in=896) (out=277) (deflated 69%)
total bytes=8320, compressed=1241 -> 85% savings
將檔案移動到到dflist.zip中
bash-3.00# zip -mv dflist.zip dflist.txt
zip info: local extra (21 bytes) != central extra (13 bytes): dflist.tar
zip info: local extra (21 bytes) != central extra (13 bytes): dflist1.txt
zip info: local extra (21 bytes) != central extra (13 bytes): dflist2.txt
zip info: local extra (21 bytes) != central extra (13 bytes): dflist3.txt
adding: dflist.txt (in=896) (out=277) (deflated 69%)
total bytes=9216, compressed=1518 -> 84% savings
zip diagnostic: deleting file dflist.txt
4.查看zip內容
bash-3.00# unzip -l dflist.zip
Length Date Time Name
-------- ---- ---- ----
5632 03-25-10 13:53 dflist.tar
896 03-25-10 13:47 dflist1.txt
896 03-25-10 13:47 dflist2.txt
896 03-25-10 14:27 dflist3.txt
896 03-25-10 12:00 dflist.txt
-------- -------
9216 5 files
5.解壓縮指令:
bash-3.00# unzip dflist.zip
Archive: dflist.zip
replace dflist.tar? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
inflating: dflist.tar
inflating: dflist1.txt
inflating: dflist2.txt
inflating: dflist3.txt
inflating: dflist.txt
留言列表