天天看點

CentOS7 學習 10 常用指令 7 壓縮、解壓縮

索引:

gzip(壓縮)/gunzip(解壓):

zip(壓縮)/unzip(解壓):(在項目打包釋出中常用,這個和windows一樣)

tar -zcvf xx.tar.gz 要壓縮的檔案file

tar -zxvf xx.tar.gz [-C 解壓到的路徑dir]

壓縮方式1:

gzip(壓縮)/gunzip(解壓):

gzip 檔案file:

功能:将檔案壓縮成*.gz檔案(不保留原先的檔案);

gunzip xxx.gz:

功能:将.gz檔案解壓。

案例1:

将hello.txt壓縮為hello.txt.gz:

CentOS7 學習 10 常用指令 7 壓縮、解壓縮

案例2:

将hello.txt.gz解壓:

CentOS7 學習 10 常用指令 7 壓縮、解壓縮

壓縮方式2:

zip(壓縮)/unzip(解壓):(在項目打包釋出中常用,這個和windows一樣)

zip [選項] xxx.zip 要壓縮的檔案file或dir:(會保留之前的檔案)

常用選項:-r,表示遞歸壓縮(壓縮目錄)

unzip [選項] xxx.zip:(會保留壓縮檔案)

常用選項:-d<目錄>,表示解壓到指定目錄

案例1:

将/home下的所有檔案壓縮成myPack.zip

CentOS7 學習 10 常用指令 7 壓縮、解壓縮
CentOS7 學習 10 常用指令 7 壓縮、解壓縮

案例2:

将myPack.zip解壓到/home/happy下

CentOS7 學習 10 常用指令 7 壓縮、解壓縮
CentOS7 學習 10 常用指令 7 壓縮、解壓縮

壓縮方式3:

tar指令:

tar [選項] xxx.tar.gz 要壓縮的檔案:

常用的壓縮組合拳:

tar -zcvf xx.tar.gz 要壓縮的檔案file

常用的解壓組合拳:

tar -zxvf xx.tar.gz [-C 解壓到的路徑dir]

常用選項:

CentOS7 學習 10 常用指令 7 壓縮、解壓縮

案例1:将1.txt,2.txt打包并壓縮為12.tar.gz:

CentOS7 學習 10 常用指令 7 壓縮、解壓縮

案例2:将/home檔案夾打包并壓縮(略)

案例3:将12.tar.gz解壓到/home/happy目錄下:(解壓到特定目錄,要加-C)

CentOS7 學習 10 常用指令 7 壓縮、解壓縮

繼續閱讀