SOLARIS下压缩/解压缩命令详解

1)zip命令
zip -r myfile.zip ./*
----将当前目录下的所有文件和文件夹全部压缩成myfile.zip文件。
----r表示递归压缩子目录下所有文件。
zip -d myfile.zip smart.txt
----删除压缩文件中smart.txt文件
zip -m myfile.zip ./rpm_info.txt
----向压缩文件中myfile.zip中添加rpm_info.txt文件

要使用 zip 来压缩文件,在 shell 提示下键入下面的命令
zip -r filename.zip filesdir
----filename.zip 代表你创建的文件,filesdir 代表你想放置新 zip 文件的目录。-r 选项指定你想递归地(recursively)包括所有包括在 filesdir 目录中的文件。

也可以使用 zip 命令同时处理多个文件和目录,方法是将它们逐一列出,并用空格间隔:
zip -r filename.zip file1 file2 file3 /usr/work/school
----此命令把 file1、file2、 file3、以及 /usr/work/school 目录的内容(假设这个目录存在)压缩起来,然后放入 filename.zip 文件中。

----详细命令请man zip
2)unzip命令
unzip -o -d /home/sunny myfile.zip
----把myfile.zip文件解压到 /home/sunny/
----o:不提示的情况下覆盖文件;
----d:-d /home/sunny 指明将文件解压缩到/home/sunny目录下;
3)tar 命令
     tar 可以为文件和目录创建档案。利用tar,用户可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件。tar最初被 用来在磁带上创建档案,现在,用户可以在任何设备上创建档案,如软盘。利用tar命令,可以把一大堆的文件和目录全部打包成一个文件,这对于备份文件或将 几个文件组合成为一个文件以便于网络传输是非常有用的。Linux上的tar是GNU版本的。

tar 命令详解

        -c: 建立压缩档案
        -x:解压
        -t:查看内容
        -r:向压缩归档文件末尾追加文件
        -u:更新原压缩包中的文件
        这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个。下面的参数是根据需要在压缩或解压档案时可选的。

        -c: 建立压缩档案
        -x:解压
        -t:查看内容
        -r:向压缩归档文件末尾追加文件
        -u:更新原压缩包中的文件

        下面的参数-f是必须的
        -f: 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名。
# tar -cf all.tar *.jpg
----这条命令是将所有.jpg的文件打成一个名为all.tar的包。-c是表示产生新的包,-f指定包的文件名。
# tar -rf all.tar *.gif
----这条命令是将所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。
# tar -uf all.tar logo.gif
----这条命令是更新原来tar包all.tar中logo.gif文件,-u是表示更新文件的意思。
# tar -tf all.tar
----这条命令是列出all.tar包中所有文件,-t是列出文件的意思
# tar -xf all.tar
----这条命令是解出all.tar包中所有文件,-t是解开的意思


压缩
tar –cvf jpg.tar *.jpg //将目录里所有jpg文件打包成tar.jpg
tar –czf jpg.tar.gz *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩,生成一个gzip压缩过的包,命名为jpg.tar.gz
tar –cjf jpg.tar.bz2 *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用bzip2压缩,生成一个bzip2压缩过的包,命名为jpg.tar.bz2
tar –cZf jpg.tar.Z *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用compress压缩,生成一个umcompress压缩过的包,命名为jpg.tar.Z
rar a jpg.rar *.jpg //rar格式的压缩,需要先下载rar for linux
zip jpg.zip *.jpg //zip格式的压缩,需要先下载zip for 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 file.zip //解压zip
gunzip file.tar.gz  //解压gz文件

总结
1、*.tar 用 tar –xvf 解压
2、*.gz 用 gzip -d或者gunzip 解压
3、*.tar.gz和*.tgz 用 tar –xzf 解压
4、*.bz2 用 bzip2 -d或者用bunzip2 解压
5、*.tar.bz2用tar –xjf 解压
6、*.Z 用 uncompress 解压
7、*.tar.Z 用tar –xZf 解压
8、*.rar 用 unrar e解压
9、*.zip 用 unzip 解压
4)gzip/gunzip
gzip 命令详解
减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间。gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用。
语法:gzip [选项] 压缩(解压缩)的文件名
各选项的含义:
-c 将输出写到标准输出上,并保留原有文件。
-d 将压缩文件解压。
-l 对每个压缩文件,显示下列字段:
     压缩文件的大小
     未压缩文件的大小
     压缩比
     未压缩文件的名字
-r 递归式地查找指定目录并压缩其中的所有文件或者是解压缩。
-t 测试,检查压缩文件是否完整。
-v 对每一个压缩和解压的文件,显示文件名和压缩比。
-num 用指定的数字num调整压缩的速度,-1或--fast表示最快压缩方法(低压缩比),-9或--best表示最慢压缩方法(高压缩比)。系统缺省值为6。
假设一个目录/home下有文件mm.txt、sort.txt、xx.com。
例1:把/home目录下的每个文件压缩成.gz文件。
$ cd /home
$ gzip *
$ ls
m.txt.gz sort.txt.gz xx.com.gz
例2:把例1中每个压缩的文件解压,并列出详细的信息。
$ gzip -dv *
mm.txt.gz 43.1%-----replaced with mm.txt
sort.txt.gz 43.1%-----replaced with sort.txt
xx.com.gz 43.1%-----replaced with xx.com
$ ls
mm.txt sort.txt xx.com
 
例3:详细显示例1中每个压缩的文件的信息,并不解压。
$ gzip -l *
compressed uncompr. ratio uncompressed_name
277 445 43.1% mm.txt
278 445 43.1% sort.txt
277 445 43.1% xx.com
$ ls
mm.txt.gz sort.txt.gz xx.com.gz
例4:压缩一个tar备份文件,如usr.tar,此时压缩文件的扩展名为.tar.gz
$ gzip usr.tar
$ ls
usr.tar.gz
ps:
tar -cvf xx.jar | gzip - dc做的(好象是这样,具体不太清楚)传到我手里以后我用winrar3.0打开时到.tar时报CRC错,我放在UNIX下用gunzip xx.jar.tar.gz时说ucompress crc error,我认为是其他同事给我时坏了,没想到他过来用gzip -dc xx.jar.tar.gz | tar xvf - 就解开了。
gzip -dc 和gunzip有什么区别
刚才验证了,的确是传输中引起的文件损坏,使用gzip -dc xx.jar.tar.gz | tar -xvf - 可以解开,但是文件还是坏的,使用gunzip根本不解压,直接报错,这就是区别。

gunzip命令详解
功能说明:解压文件。
语    法:gunzip [-acfhlLnNqrtvV][-s <压缩字尾字符串>][文件...] 或 gunzip [-acfhlLnNqrtvV][-s <压缩字尾字符串>][目录]
补充说明:gunzip是个使用广泛的解压缩程序,它用于解开被gzip压缩过的文件,这些压缩文件预设最后的扩展名为 ".gz"。事实上gunzip就是gzip的硬连接,因此不论是压缩或解压缩,都可通过gzip指令单独完成。
参    数:

-a或--ascii    使用ASCII文字模式。    
-c或--stdout或--to-stdout    把解压后的文件输出到标准输出设备。    
-f或-force    强行解开压缩文件,不理会文件名称或硬连接是否存在以及该文件是否为符号连接。    
-h或--help    在线帮助。    
-l或--list    列出压缩文件的相关信息。    
-L或--license    显示版本与版权信息。    
-n或--no-name    解压缩时,若压缩文件内含有远来的文件名称及时间戳记,则将其忽略不予处理。    
-N或--name    解压缩时,若压缩文件内含有原来的文件名称及时间戳记,则将其回存到解开的文件上。    
-q或--quiet    不显示警告信息。    
-r或--recursive    递归处理,将指定目录下的所有文件及子目录一并处理。    
-S<压缩字尾字符串>或--suffix<压缩字尾字符串>    更改压缩字尾字符串。    
-t或--test    测试压缩文件是否正确无误。    
-v或--verbose    显示指令执行过程。    
-V或--version 显示版本信息。
5)gzmore、gzcat
gzmore - file perusal filter for crt viewing    of    compressed
         text
DESCRIPTION
         Gzmore is a filter which allows examination of compressed or
         plain text files one screenful at a time on a soft-copy ter-
         minal.    gzmore works on files compressed with compress, pack
         or gzip, and also on uncompressed files.    If a file does not
         exist, gzmore looks for a file of the    same    name    with    the
         addition of a .gz, .z or .Z suffix.

         Gzmore normally pauses after    each    screenful,    printing    --
         More--    at the bottom of the screen.    If the user then types
         a carriage return, one more line is displayed.    If the    user
         hits    a space, another screenful is displayed.    Other possi-
         bilities are enumerated later.

         Gzmore looks in the file /etc/termcap to determine    terminal
         characteristics,    and    to determine the default window size.
         On a terminal capable of displaying 24    lines,    the     default
         window    size    is    22    lines.     To use a pager other than the
         default more, set environment variable PAGER to the name    of
         the desired program, such as less.

         Other sequences which may be typed when gzmore    pauses,    and
         their    effects,    are    as    follows    (i is an optional integer
         argument, defaulting to 1)
这个命令的功能及查看.gz文件内的内容。用起来和more一样。类似的命令还有gzcat等。
在linux中则有zgrep查看.gz文件内容。也有类似的zcat命令用法如下
Similar to more. Uncompress files and print them one screenful at a time. Works on files compressed with compress, gzip, or pack, and with uncompressed files.
Commands space
Print next screenful.
ispace
Print next i lines.
Return
Print one more line.
d, ^D
Print next i, or 11, lines.
iz
Print next i lines or a screenful. If i is specified, treat it as the new window size for the rest of the current file, then revert back to the default.
is
Skip i lines. Print next screenful.
if
Skip i screens. Print next screenful.
q, Q, :q, :Q
Go to next file or, if current file is the last, exit zmore.
e, q
Exit zmore when the prompt "--More--(Next file: file)" is displayed.
s
Skip next file and continue when the prompt "--More--(Next file: file)" is displayed.
=
Print line number.
i/expr
Search forward for ith occurrence (in all files) of expr, which should be a regular expression. Display occurrence, including the two previous lines of context.
in
Search forward for the ith occurrence of the last regular expression searched for.
!command
Execute command in shell. If command is not specified, execute last shell command. To invoke a shell without passing it a command, enter \!.
.
Repeat the previous command.




本文出自 “Focus on Oracle” 博客,请务必保留此出处http://alexy.blog.51cto.com/6115453/1050445

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值