通過SSH解壓縮.tar.gz、.gz、.zip文件的方法


一般在linux下,常用的壓縮格式有如下幾個: .tar.gz、.gz、.zip

解壓 .tar.gz 文件命令: tar -zxvf xxx.tar.gz

解壓 .gz 文件命令: gunzip xxx.gz

解壓 .zip 文件命令:unzip xxx.zip

unzip解壓時,有時希望覆蓋原文件,否則還需要設置權限,重新上傳等操作,很麻煩。
如果在unzip命令后,增加 -o的參數,則不再進行詢問,直接覆蓋原文件解壓縮,節省了很多事兒。
命令: unzip -o xxx.zip

用tar壓縮一個文件夾:tar -zcvf public_html.tar.gz public_html

linux下 zip壓縮用法

1.zip
zip -r xxx.zip ./*
將當前目錄下的所有文件和文件夾全部壓縮成xxx.zip文件,-r表示遞歸壓縮子目錄下所有文件。

2.unzip
unzip -o -d /home/admin xxx.zip
把xxx.zip文件解壓到 /home/admin/
-o:不提示的情況下覆蓋文件
-d:-d /home/admin 指明將文件解壓縮到/home/admin目錄下。

3.其他
zip -d xxx.zip smart.txt
刪除壓縮文件中smart.txt文件
zip -m xxx.zip ./phpinfo.txt
向壓縮文件中xxx.zip中添加phpinfo.txt文件。

 

附unzip更多詳解:

unzip命令:解壓縮文件
他是解壓zip壓縮的文件,和zip互逆的一對工具。

命令:
unzip [選項] zip壓縮文件
-c 解壓到標准輸出上
-l 小寫的L,顯示壓縮文件內的文件。
-z 顯示壓縮文件的備注文字


例:
1、解壓文件
linux@ubuntu:~/afish$ unzip c.zip
Archive:  c.zip
這是一個測試的壓縮文件 .
   creating: c/
  inflating: c/a.out                 
  inflating: c/lib.h                 
  inflating: c/abc.c                 
  inflating: c/read.c                
   creating: c/head/
  inflating: c/head/conf.h           
  inflating: c/main.c                
 extracting: c/a.c                   
  inflating: c/write.c               
  inflating: c/read                  
  inflating: c/afish     
   
2、解壓文件到指定的目錄
linux@ubuntu:~$ unzip -d afish snow.zip
Archive:  snow.zip
   creating: afish/snow/
  inflating: afish/snow/snow.xml.in    
   creating: afish/snow/build/
  inflating: afish/snow/build/snow_options.lo  
  inflating: afish/snow/build/snow_options.h  
  inflating: afish/snow/build/snow.o   
   creating: afish/snow/build/.libs/
  inflating: afish/snow/build/.libs/libsnow.lai  
.....
加一個參數:-d 目標位置即可。

3、顯示注釋內容
linux@ubuntu:~$ zip -z snow.zip #先給snow.zip添加注釋
enter new zip file comment (end with .):
這是一個雪花效果,很好看啊
.  #這個位置輸入.結束。
linux@ubuntu:~$ unzip -z snow.zip  #查看注釋
Archive:  snow.zip
一個雪花效果,很好看啊

4、顯示文件中內容(不解壓)
linux@ubuntu:~$ unzip -l c.zip
Archive:  c.zip
這是一個測試的壓縮文件 .
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2011-01-16 15:02   c/
     7630  2011-01-16 15:02   c/a.out
     1255  2011-01-16 14:38   c/lib.h
      109  2011-01-16 13:56   c/abc.c
      610  2011-01-16 14:31   c/read.c
        0  2011-01-16 13:48   c/head/
      593  2011-01-16 13:48   c/head/conf.h
      435  2011-01-16 13:29   c/main.c
       73  2011-01-16 14:55   c/a.c
      527  2011-01-16 14:51   c/write.c
     7542  2011-01-16 14:40   c/read
       90  2011-01-16 15:02   c/afish
---------                     -------
    18864                     12 files

我們也可以用一個zipinfo命令來顯示詳細信息:
如:
linux@ubuntu:~$ zipinfo c.zip
Archive:  c.zip
Zip file size: 9589 bytes, number of entries: 12
drwxr-xr-x  3.0 unx        0 bx stor 11-Jan-16 15:02 c/
-rwxr-xr-x  3.0 unx     7630 bx defN 11-Jan-16 15:02 c/a.out
-rw-r--r--  3.0 unx     1255 tx defN 11-Jan-16 14:38 c/lib.h
-rw-r--r--  3.0 unx      109 tx defN 11-Jan-16 13:56 c/abc.c
-rw-r--r--  3.0 unx      610 tx defN 11-Jan-16 14:31 c/read.c
drwxr-xr-x  3.0 unx        0 bx stor 11-Jan-16 13:48 c/head/
-rw-r--r--  3.0 unx      593 tx defN 11-Jan-16 13:48 c/head/conf.h
-rw-r--r--  3.0 unx      435 tx defN 11-Jan-16 13:29 c/main.c
-rw-r--r--  3.0 unx       73 tx stor 11-Jan-16 14:55 c/a.c
-rw-r--r--  3.0 unx      527 tx defN 11-Jan-16 14:51 c/write.c
-rwxr-xr-x  3.0 unx     7542 bx defN 11-Jan-16 14:40 c/read
-rw-r--r--  3.0 unx       90 bx defN 11-Jan-16 15:02 c/afish
12 files, 18864 bytes uncompressed, 7828 bytes compressed:  58.5%

注意 :
1、unzip解壓必須由zip生成的壓縮文件
2、一次只能對一個zip文件解壓

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM