linux檔案解 壓縮

2021-09-06 14:34:56 字數 4636 閱讀 4814

常用:

解壓tar.gz包使用命令:tar -zxvf  file.tar.gz-z 指有gzip的屬性  -x 解開乙個壓縮檔案的引數  -v解壓過程中顯示檔案  -f放最後接filename

解壓tar包使用命令:tar -xvf file.tar

檢視tar包裡打包了哪些檔案: tar -tf file.tar   或tar -tvf file.tar

解壓zip檔案使用命令:unzip file.zip       aix下解壓zip檔案: jar -xvf filename.zip

gunzip file.zip

解壓rar檔案使用命令:unrar e file.rar把file.rar中的所有檔案解壓出來

tar包是未壓縮過的,而zip或gz是打包後再進行壓縮的檔案

打包與壓縮

打包目錄使用命令tar -cvf  dir1.tar dir1-c 是comprise 壓縮/打包

打包並壓縮使用命令tar -zcvf  dir1.tar.gz dir1-z是打包並以gzip壓縮  

排除某個不想新增到壓縮檔案的目錄:tar -zcvf  dir3.tar.gz dir3 --exclude=dir3/dirx/dirr  --exclude=dir3/dirx/diry----錯誤,看最後例項

zip壓縮使用命令zip   -r  myfile.zip dirname-r表示遞迴壓縮目錄下所有檔案

gzip壓縮     只壓縮檔案,不保留原始檔,不壓縮目錄

把project_a資料夾下的檔案打包成project.war

1.打包jar- cvf project.war /project_a

-c   建立war包

-v   顯示過程資訊

-f   指 定 jar檔名,通常這個引數是必須的

-m  不產生所有項的清單 (manifest〕檔案,此引數會忽略 -m引數

-0   這個是阿拉伯數字 ,只打包不壓縮的意思

2.解壓war包:

jar -xvf project.war

[root@rusky share]# cd testdir3

[root@rusky testdir3]# ls

****dir ****.txt

[root@rusky testdir3]# gzip *

gzip: ****dir is a directory -- ignored

[root@rusky testdir3]# gzip -r *   有目錄,加r遞迴壓縮目錄中檔案

[root@rusky testdir3]# ls

****dir ****.txt.gz

如果只壓縮單個檔案,非目錄,則:gzip  123.txt  壓縮後原始檔123.txt變成123.txt.gz   

bzip2解壓縮:

bzip2是乙個壓縮能力更強的壓縮程式,.bz2結尾的檔案就是bzip2壓縮的結果。 與bzip2相對的解壓程式是bunzip2。tar中使用-j這個引數來呼叫gzip。下面來舉例

說明一下:-j表示有bz2屬性 

這條命令是將所有.jpg的檔案打成乙個tar包,並且將其用bzip2壓縮,生成乙個bzip2壓縮過的包,包名為all.tar.bz2 

# tar -xjf all.tar.bz2 

這條命令是將上面產生的包解開。 

aix解壓:.tar.gz格式方式

gunzip testfile.tar.gz     得到:testfile.tar

tar -xvf testfile.tar   得到testfile

*************************

tar壓縮目錄時排除我們不需要的某個目錄或檔案:

[root@rusky home]# tree test/      //檢視test目錄結構

test/

├── test1

│   ├── file1

│   ├── file1.1

│   └── file1.2

├── test2

│   ├── file2-1

│   ├── test2-1

│   └── test2-2

└── test3

5 directories, 4 files

[root@rusky home]# tar -zcvf rusky1.tar.gz test/

test/

test/test1/

test/test1/file1

test/test1/file1.1

test/test1/file1.2

test/test2/

test/test2/test2-1/

test/test2/test2-2/

test/test2/file2-1

test/test3/

[root@rusky home]# tar -zcvf rusky1.tar.gz test/ --exclude=test1 //排除test目錄下的test1目錄。"="等號後面跟著的是要壓縮目錄下的某個具體目錄名,而不是路徑

test/

test/test2/

test/test2/test2-1/

test/test2/test2-2/

test/test2/file2-1

test/test3/

[root@rusky home]# tar -zcvf rusky1.tar.gz test/ --exclude=test1 --exclude=test3 //排除多個test2和test3目錄

test/

test/test2/

test/test2/test2-1/

test/test2/test2-2/

test/test2/file2-1

[root@rusky home]# tar -zcvf rusky1.tar.gz test/ --exclude=file* //排除以file開頭的所有檔案,包括字目錄裡的

test/

test/test1/

test/test2/

test/test2/test2-1/

test/test2/test2-2/

test/test3/

[root@rusky home]# tar -zcvf rusky1.tar.gz test/ --exclude=/home/test/test1/ --exclude=/home/test/test2/ //exclude後面不能是路徑,否則不生效

test/

test/test1/

test/test1/file1

test/test1/file1.1

test/test1/file1.2

test/test2/

test/test2/test2-1/

test/test2/test2-2/

test/test2/file2-1

test/test3/

[root@rusky home]# tar -zcvf rusky1.tar.gz test/ --exclude=/home/test/test1 --exclude=/home/test/test2 //同上,exclude後面跟路徑不生效

test/

test/test1/

test/test1/file1

test/test1/file1.1

test/test1/file1.2

test/test2/

test/test2/test2-1/

test/test2/test2-2/

test/test2/file2-1

test/test3/

[root@rusky home]# tar -zcvf rusky1.tar.gz test/ --exclude=./test/test1/ --exclude=./test/test2 //同上,路徑不生效,預設壓縮全部

test/

test/test1/

test/test1/file1

test/test1/file1.1

test/test1/file1.2

test/test2/

test/test2/test2-1/

test/test2/test2-2/

test/test2/file2-1

test/test3/

[root@rusky home]#

Linux 檔案壓縮解壓縮

tar格式 解包1 tar xvf filename.tar 解包2 tar xvf filename.tar c dirname tar解壓縮到指定目錄 打包 tar cvf filename.tar dirname tar是打包,不是壓縮!gz格式 解壓1 gunzip filename.gz ...

Linux檔案解壓縮

linux上常見的壓縮命令就是gzip,bzip2 gzip 和 zcat gzip cdtv 檔名 引數 c 將壓縮資訊顯示在螢幕 d 解壓 t 可以用來檢驗乙個壓縮檔案的一致性,看看檔案有誤錯誤 v 可以顯示出原檔案 壓縮檔案的壓縮比等資訊 壓縮等級,1最快,但最差。9最慢,但壓縮比最好是預設的...

linux 檔案解壓縮

目前 linux 下最常見的壓縮包格式自然非 tar.gz 莫屬,但由於 bzip2 強大的壓縮比率,目前 tar.bz2 愈發有取代之勢。還有單純的 tar 格式也很常見。它們目前的操作都主要是由 tar 程式 配合 gzip bzip2 來完成的。下面來詳細的說下tar 這個命令 tar c 建...