日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > centos >内容正文

centos

Centos之压缩和解压缩命令

發(fā)布時間:2025/6/17 centos 73 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Centos之压缩和解压缩命令 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

常用壓縮格式:.zip .gz .bz2

常用壓縮格式:.tar.gz ?.tar.bz2

1、zip格式壓縮



zip壓縮文件名 源文件


壓縮文件


zip -r 壓縮文件名 源目錄


壓縮目錄


[root@localhost ~]# zip 牛牛.zip 牛牛


-bash: zip: 未找到命令


我們壓縮 牛牛?


報錯 zip 未找到命令


我們用yum命令安裝下


yum -y install zip


[root@localhost ~]# zip 牛牛.zip 牛牛


? adding: 牛牛 (stored 0%)


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?牛牛.zip


[root@localhost ~]#?


成功用zip命令壓縮了牛牛文件


[root@localhost ~]# mkdir 書籍


[root@localhost ~]# touch 書籍/java.pdf


[root@localhost ~]# touch 書籍/php.pdf


[root@localhost ~]# touch 書籍/asp.pdf


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?牛牛.zip ?書籍


[root@localhost ~]# ls /root/書籍/


asp.pdf ?java.pdf ?php.pdf


[root@localhost ~]#?


我們新建了一個書籍目錄 然后目錄下放了幾個文件


[root@localhost ~]# zip -r 書籍.zip 書籍


? adding: 書籍/ (stored 0%)


? adding: 書籍/java.pdf (stored 0%)


? adding: 書籍/php.pdf (stored 0%)


? adding: 書籍/asp.pdf (stored 0%)


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?牛牛.zip ?書籍 ?書籍.zip


[root@localhost ~]#?


壓縮目錄


2、.zip解壓縮


unzip 壓縮文件



解壓縮.zip文件


我們先刪除原文件


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?牛牛.zip ?書籍 ?書籍.zip


[root@localhost ~]# rm -rf 牛牛


[root@localhost ~]# rm -rf 書籍


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛.zip ?書籍.zip


[root@localhost ~]#?


[root@localhost ~]# unzip 牛牛.zip


-bash: unzip: 未找到命令


發(fā)現(xiàn)unzip沒安裝


安裝下?


yum install -y unzip



[root@localhost ~]# unzip 牛牛.zip


Archive: ?牛牛.zip


?extracting: 牛牛 ? ? ? ? ? ? ? ? ?


[root@localhost ~]# unzip 書籍.zip


Archive: ?書籍.zip


? ?creating: 書籍/


?extracting: 書籍/java.pdf ? ? ? ??


?extracting: 書籍/php.pdf ? ? ? ? ?


?extracting: 書籍/asp.pdf ? ? ? ? ?


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?牛牛.zip ?書籍 ?書籍.zip


[root@localhost ~]#?


解壓成功


3、.gz格式壓縮



gzip 源文件


壓縮為.gz格式的壓縮文件,源文件會消失


gzip -c 源文件 > 壓縮文件


壓縮為.gz格式,源文件保留


例如:gzip -c 書籍 > 書籍.gz


gzip -r 目錄



壓縮目錄下所有的子文件,但是不能壓縮目錄



[root@localhost ~]# rm -rf *.zip


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍


[root@localhost ~]#?


先刪除zip


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍


[root@localhost ~]# gzip 牛牛


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛.gz ?書籍


[root@localhost ~]#?


壓縮文件


[root@localhost ~]# gzip -r 書籍


[root@localhost ~]# ls


aaa ?anaconda-ks.cfg ?牛牛.gz ?書籍


[root@localhost ~]# ls 書籍/


asp.pdf.gz ?java.pdf.gz ?php.pdf.gz


[root@localhost ~]#?


壓縮目錄


4、.gz格式解壓縮



gzip -d 壓縮文件


解壓縮文件


gunzip 壓縮文件


解壓縮文件


[root@localhost ~]# gzip -d 牛牛.gz


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍


[root@localhost ~]#?


用gunzip 牛牛.gz 效果一樣


[root@localhost ~]# gunzip -r 書籍


[root@localhost ~]# ls?


anaconda-ks.cfg ?牛牛 ?書籍


[root@localhost ~]# ls 書籍/


asp.pdf ?java.pdf ?php.pdf


[root@localhost ~]#?


解壓目錄


5、.bz2格式壓縮



bzip2 源文件


壓縮為.bz2格式,不保留源文件


bzip2 -k 源文件


壓縮之后保留源文件


注意:bzip2命令不能壓縮目錄

[root@localhost ~]# bzip2 牛牛


-bash: bzip2: 未找到命令


[root@localhost ~]# yum -y install bzip2


命令不存在,我們就安裝下;


[root@localhost ~]# bzip2 牛牛


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛.bz2 ?書籍


[root@localhost ~]#?


源文件沒了,假如要保留源文件 bzip2 -k 牛牛

.bz2格式解壓縮


bzip2 -d 壓縮文件


#解壓縮,-k保留壓縮文件


bunzip2 壓縮文件


#解壓縮,-k 保留壓縮文件


[root@localhost ~]# bzip2 -d 牛牛.bz2


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍


[root@localhost ~]#?



6、打包命令tar



tar -cvf 打包文件名 源文件


選項:


-c :打包


-v :顯示過程


-f :指定打包后的文件名


例如


tar -cvf 牛牛.tar 牛牛


[root@localhost ~]#?


[root@localhost ~]# tar -cvf 書籍.tar 書籍


書籍/


書籍/java.pdf


書籍/php.pdf


書籍/asp.pdf


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍 ?書籍.tar


[root@localhost ~]#?


打包書籍目錄


[root@localhost ~]# gzip 書籍.tar?


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍 ?書籍.tar.gz


[root@localhost ~]#?


把書籍.tar壓縮gz


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍 ?書籍.tar.gz


[root@localhost ~]# gzip -d 書籍.tar.gz


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍 ?書籍.tar


[root@localhost ~]# bzip2 書籍.tar


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍 ?書籍.tar.bz2


[root@localhost ~]#?


把書籍.tar壓縮成bzip2


7、解打包命令



tar -xvf 打包文件名


選項:


-x : 解打包


例如:


tar -xvf 書籍.tar


[root@localhost ~]# bzip2 -d 書籍.tar.bz2


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍 ?書籍.tar


[root@localhost ~]# tar -xvf 書籍.tar


書籍/


書籍/java.pdf


書籍/php.pdf


書籍/asp.pdf


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍 ?書籍.tar


[root@localhost ~]# ls 書籍/


asp.pdf ?java.pdf ?php.pdf


[root@localhost ~]#?


8、.tar.gz壓縮格式



其實.tar.gz格式是先打包為.tar格式,再壓縮為.gz格式


tar -zcvf 壓縮名.tar.gz 源文件


選項:


-z :壓縮為.tar.gz格式


tar -zxvf 壓縮包名.tar.gz


選項:


-x:解壓縮.tar.gz格式


.tar.bz2壓縮格式


其實.tar.bz2格式是先打包為.tar格式,再壓縮為.bz2格式


tar -jcvf 壓縮名.tar.bz2 源文件


選項:


-j :壓縮為.tar.bz2格式


tar -zxvf 壓縮包名.tar.bz2


選項:


-x:解壓縮.tar.bz2格式


[root@localhost ~]# rm -rf 書籍.tar


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍


[root@localhost ~]# tar -zcvf 書籍.tar.gz 書籍


書籍/


書籍/java.pdf


書籍/php.pdf


書籍/asp.pdf


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍 ?書籍.tar.gz


[root@localhost ~]#?


9、壓縮tar.gz



[root@localhost ~]# rm -rf 書籍


[root@localhost ~]# tar -zxvf 書籍.tar.gz


書籍/


書籍/java.pdf


書籍/php.pdf


書籍/asp.pdf


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍 ?書籍.tar.gz


[root@localhost ~]#?


10、解壓縮tar.gz



[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍 ?書籍.tar.gz


[root@localhost ~]# tar -jcvf 書籍.tar.bz2 書籍


書籍/


書籍/java.pdf


書籍/php.pdf


書籍/asp.pdf


[root@localhost ~]# ls


anaconda-ks.cfg ?牛牛 ?書籍 ?書籍.tar.bz2 ?書籍.tar.gz


[root@localhost ~]#?


壓縮tar.bz2


[root@localhost ~]# tar -jxvf 書籍.tar.bz2 -C /tmp/


書籍/


書籍/java.pdf


書籍/php.pdf


書籍/asp.pdf


[root@localhost ~]# ls /tmp/


ks-script-NSb_Xk


systemd-private-7113799c2057477ab6ee497261ae7a13-vmtoolsd.service-pskbnQ


systemd-private-b37fa00ba37a4d119a61ec71ea2c7116-vmtoolsd.service-t7gach


systemd-private-dec75be7d6a64814b5ba654e693bd541-vmtoolsd.service-xituVu


yum.log


書籍


[root@localhost ~]# ls /tmp/書籍/


asp.pdf ?java.pdf ?php.pdf


[root@localhost ~]#?


解壓縮到其他目錄


壓縮多文件到指定目錄


[root@localhost ~]# tar -zcvf /tmp/test.tar.gz 書籍 anaconda-ks.cfg?


書籍/


書籍/java.pdf


書籍/php.pdf


書籍/asp.pdf


anaconda-ks.cfg


[root@localhost ~]# ls /tmp/


ks-script-NSb_Xk


systemd-private-7113799c2057477ab6ee497261ae7a13-vmtoolsd.service-pskbnQ


systemd-private-b37fa00ba37a4d119a61ec71ea2c7116-vmtoolsd.service-t7gach


systemd-private-dec75be7d6a64814b5ba654e693bd541-vmtoolsd.service-xituVu


test.tar.gz


yum.log


書籍


[root@localhost ~]#?


查看壓縮包(不解壓)


[root@localhost ~]# cd /tmp/


[root@localhost tmp]# tar -ztvf test.tar.gz


drwxr-xr-x root/root ? ? ? ? 0 2017-06-22 14:53 書籍/


-rw-r--r-- root/root ? ? ? ? 0 2017-06-22 14:42 書籍/java.pdf


-rw-r--r-- root/root ? ? ? ? 0 2017-06-22 14:42 書籍/php.pdf


-rw-r--r-- root/root ? ? ? ? 0 2017-06-22 14:42 書籍/asp.pdf


-rw------- root/root ? ? ?1235 2017-06-22 01:34 anaconda-ks.cfg


[root@localhost tmp]#?


Reference:

[1] Java1234_小鋒, Centos之壓縮和解壓縮命令, http://blog.java1234.com/blog/articles/305.html

轉載于:https://www.cnblogs.com/ryelqy/p/10104136.html

總結

以上是生活随笔為你收集整理的Centos之压缩和解压缩命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。