1. 程式人生 > 其它 >linux gz解壓 重新命名_linux如何解壓tar.gz到指定資料夾或目錄

linux gz解壓 重新命名_linux如何解壓tar.gz到指定資料夾或目錄

技術標籤:linux gz解壓 重新命名

請關注本頭條號,每天堅持更新原創乾貨技術文章。

如需學習視訊,請在微信搜尋公眾號“智傳網優”直接開始自助視訊學習

1. 前言

本文主要講解如何解壓tar.gz到指定資料夾或目錄,tar是Linux系統上的一種打包與壓縮工具。

976591022948d071b1b0bd8cb8996e5f.png

linux解壓tar.gz到指定資料夾或目錄

2. linux解壓tar檔案使用案例

Linux下使用tar命令把當前目錄下的zcwyou.tar.gz解壓到指定的目錄/123/abc/ ,前提要保證存在/123/abc/這個目錄。

[[email protected] ~]# tar -zxvf zcwyou.tar.gz -C /123/abc
96cde2b749c2f9daa23eaf3ea7ad1110.png

linux解壓tar.gz到指定資料夾

當前目錄下的abc檔案打包到根目錄下並命名為abc.tar.gz[[email protected] ~]# tar zcvf abc.tar.gz ./abc
8375d7a533e4c078a2edcac5ce056ea8.png

linux解壓tar.gz到指定資料夾

3. tar解壓縮命令

-c: 建立壓縮檔案

-x:解壓

-t:檢視內容

-r:向壓縮歸檔檔案末尾追加檔案

-u:更新原壓縮包中的檔案

這五個是獨立的命令,壓縮解壓都要用到其中一個,可以和別的命令連用但只能用其中一個。下面的引數是根據需要在壓縮或解壓檔案時可選的。

-z:有gzip屬性的

-j:有bz2屬性的

-Z:有compress屬性的

-v:顯示所有過程

-O:將檔案解開到標準輸出

下面的引數-f是必須的

-f: 使用檔案名字,切記,這個引數是最後一個引數,後面只能接檔案名。

把所有.jpg的檔案打成一個名為all_pic.tar的包。-c是表示產生新的包,-f指定包的檔名。

[[email protected] ~]# tar -cf all_pic.tar *.jpg

這條命令是將所有.gif的檔案增加到all.tar的包裡面去。-r是表示增加檔案的意思。

[[email protected] ~]# tar -rf all.tar *.gif

這條命令是更新原來tar包all.tar中logo.gif檔案,-u是表示更新檔案的意思。

[[email protected] ~]# tar -uf all.tar logo.gif

列出all.tar包中所有檔案,選項-t表示列出檔案。

[[email protected] ~]# tar -tf all.tar

解出all.tar包中所有檔案,選項-x表示解壓,執行以下命令:

[[email protected] ~]# tar -xf all.tar

4. 壓縮

將目錄裡所有jpg檔案打包成jpg.tar

[[email protected] ~]# tar -cvf jpg.tar *.jpg

將當前目錄裡所有jpg檔案打包成jpg.tar後,並且使用gzip演算法壓縮,生成一個gzip壓縮包,命名為jpg.tar.gz

[[email protected] ~]# tar -czf jpg.tar.gz *.jpg

將當前目錄裡所有jpg檔案打包成jpg.tar後,然後使用bzip2演算法壓縮,生成bzip2包,命名為jpg.tar.bz2

[[email protected] ~]# tar -cjf jpg.tar.bz2 *.jpg

將目錄裡所有jpg檔案打包成jpg.tar後,然後使用compress演算法壓縮,生成一個壓縮包,命名為jpg.tar.Z

[[email protected] ~]# tar -cZf jpg.tar.Z *.jpg

5. 解壓tar壓縮包

解壓 tar包

[[email protected] ~]# tar -xvf file.tar

解壓tar.gz

[[email protected] ~]# tar -xzvf file.tar.gz

解壓 tar.bz2

[[email protected] ~]# tar -xjvf file.tar.bz2

解壓tar.Z

[[email protected] ~]# tar -xZvf file.tar.Z

解壓rar

[[email protected] ~]# unrar e file.rar

解壓zip

[[email protected] ~]# unzip file.zip

6. 總結

*.tar用tar -xvf解壓

*.gz用gzip -d或者gunzip 解壓

.tar.gz和.tgz 用 tar -xzf 解壓

*.bz2 用 bzip2 -d或者用bunzip2 解壓

*.tar.bz2用tar -xjf 解壓

*.Z 用 uncompress 解壓

*.tar.Z 用tar -xZf 解壓

*.rar 用 unrar e解壓

*.zip 用unzip 解壓