linux命令之壓縮及解壓縮

2021-09-20 23:56:57 字數 1337 閱讀 2818

1 gzip

[root@localhost ~]# gzip a.sh                #壓縮後檔案字尾為.gz

[root@localhost ~]# gzip -d a.sh.gz          #解壓gz檔案

[root@localhost ~]# zcat a.sh.gz             #檢視壓縮檔案

2 bzip

[root@localhost ~]# bzip2 a.sh               #壓縮後檔案字尾為bz2

[root@localhost ~]# bzip2 a.sh.bz2 -d        #解壓檔案

[root@localhost ~]# bzcat a.sh.bz2           #檢視壓縮檔案

備註:gzip和bzip2目前不支援對目錄的壓縮

3 zip:支援對目錄的壓縮

選項:-r    遞迴壓縮

-d    從壓縮檔案中刪除指定檔案

-o    不提示的情況下覆蓋原檔案

[root@localhost /]# zip -r root.zip /root/*  #壓縮

[root@localhost ~]# unzip -o -d /c root.zip  #解壓到根下的c目錄下,-d為指定解壓的目錄

4 tar:打包與解包檔案

用法:tar [主選項+次選項] 路徑...        #主選項是必須的,次選項可以選用

主選項:-c    建立打包檔案

-x    釋放打包檔案

-t    列出打包的文件的內容

-r    追加檔案到打包檔案

--delete    從打包檔案中刪除檔案

次選項:-c    指定解壓路徑

-f    指定打包的名稱

-z    打包後通過gzip格式壓縮

-j    打包後通過bzip2格式壓縮

-p    保留原檔案的屬性,如檔案的許可權

[root@localhost /]# tar -czf etc.tar.gz /etc/        #打包並壓縮目錄

[root@localhost /]# tar -tf etc.tar.gz               #列出打包文件的內容

[root@localhost /]# tar -xzf etc.tar.gz -c /c        #把檔案解壓到c目錄下

[root@localhost /]# tar -rf a.tar /root/a.txt        #把檔案追加到歸檔包中

[root@localhost /]# tar --delete root/a.txt -f /a.tar#從打包檔案中刪除a.txt

linux壓縮解壓縮命令

zip r myfile.zip 將當前目錄下面所有的東西打包到myfile.zip unzip o d home sunny myfile.zip 把myfile.zip檔案解壓到 home sunny o 不提示的情況下覆蓋檔案 d 指名檔案解壓縮到哪個目錄 zip d myfile.zip s...

壓縮解壓縮linux命令

壓縮解壓縮linux命令 一.zip 1 把 home目錄下面的data目錄壓縮為data.zip zip r data.zip data 壓縮mydata目錄 2 把 home目錄下面的data.zip解壓到databak目錄裡面 unzip data.zip d databak 3 把 home...

Linux 壓縮解壓縮命令

解壓 tar xvf file.tar 解壓 tar包 tar xzvf file.tar.gz 解壓tar.gz tar xjvf file.tar.bz2 解壓 tar.bz2 tar xzvf file.tar.z 解壓tar.z unrar e file.rar 解壓rar unzip fi...