zoukankan      html  css  js  c++  java
  • 通过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文件解压

  • 相关阅读:
    python 中关于kafka的API
    python 中对json的操作
    python 错误--UnboundLocalError: local variable '**' referenced before assignment
    storm问题记录(1) python 不断向kafka中写消息,spout做为消费者从kafka中读消息并emit给bolt,但是部分消息没有得到bolt的处理
    nodejs+kafka+storm+hbase 开发
    python构造数据
    Head first java中提到的学习方法,很受用
    【机器学习 第2章 学习笔记】模型评估与选择
    路书
    二分搜索
  • 原文地址:https://www.cnblogs.com/afish/p/4125810.html
Copyright © 2011-2022 走看看