日期:2014-05-16  浏览次数:20762 次

linux-压缩和解压缩
linux-压缩和解压缩


1.解压缩

tar -zxvf 文件名.tar.gz
z is to handle files that were compressed using gzip.
x is to extract.
v is to be verbose about what is going on.
f is to force overwriting if it was already extracted.

2.压缩文件

tar -zcvf 文件名.tar.gz * .
* . (*后有一个空格) 表示压缩当前文件夹下的所有文件
z is to handle files that were compressed using gzip.
c is to compress.
v is to be verbose about what is going on.
f is to force overwriting if it was already extracted.

3.语法:
 
  tar [-zxcvfpP] filename  解压缩
  tar -N 'yyy/mm/dd' /path -zcvf target.tar.gz source 压缩

  参数说明:
  -z:是否同时具有 gzip
  -x:解开一个压缩文件
  -t:查看tarfile里面的文件
  -c:建立一个压缩文件
  -v:压缩过程中显示文件
  -f:使用文件名
  -p:使用原文件的原有属性
  -P:可以使用绝对路径
  -N:比后面接的日期(yyy/mm/dd)还要新的文件才会被打包进新建文件夹中

范例:
  tar -cvf directory.tar directory
只将目录整合打包成一个文件

  tar -zcvf directory.tar.gz  directory
除了将目录打包外,同时以gzip压缩。

  tar -zcvf filename.tar.gz /home/test/*
将/home/test目录下的文件全部打包并压缩为一个filename.tar.gz文件


jar的使用:

把当前目录下的所有文件打包成game.war
jar -cvfM0 game.war ./

-c   创建war包
-v   显示过程信息
-f   
-M
-0   这个是阿拉伯数字,只打包不压缩的意思


解压game.war

jar -xvf game.war

解压到当前目录