gzip
压缩后的格式为:*.gz
这种压缩方式不能保存原文件;且不能压缩目录
命令举例:
#压缩
[root@localhost tmp]# gzip buodo
[root@localhost tmp]# ls
buodo.gz
#解压
[root@localhost tmp]# gunzip buodo.gz
[root@localhost tmp]# ls buodo
tar
命令选项:
-z(gzip) 用gzip来压缩/解压缩文件
-j(bzip2) 用bzip2来压缩/解压缩文件
-v(verbose) 详细报告tar处理的文件信息
-c(create) 创建新的档案文件
-x(extract) 解压缩文件或目录
-f(file) 使用档案文件或设备,这个选项通常是必选的。
命令举例:
#压缩
[root@localhost tmp]# tar -zvcf buodo.tar.gz buodo
[root@localhost tmp]# tar -jvcf buodo.tar.bz2 buodo
#解压
[root@localhost tmp]# tar -zvxf buodo.tar.gz
[root@localhost tmp]# tar -jvxf buodo.tar.bz2
zip
与gzip相比:1)可以压缩目录; 2)可以保留原文件;
选项:
-r(recursive) 递归压缩目录内的所有文件和目录
1
命令举例:
#压缩和解压文件
[root@localhost tmp]# zip boduo.zip boduo
[root@localhost tmp]# unzip boduo.zip
#压缩和解压目录
[root@localhost tmp]# zip -r Demo.zip Demo
adding: Demo/ (stored 0%)
adding: Demo/Test2/ (stored 0%)
adding: Demo/Test1/ (stored 0%)
adding: Demo/Test1/test4 (stored 0%)
adding: Demo/test3 (stored 0%)
[root@localhost tmp]# unzip Demo.zip
Archive: Demo.zip
creating: Demo/
creating: Demo/Test2/
creating: Demo/Test1/
extracting: Demo/Test1/test4
extracting: Demo/test3
bzip2
压缩后的格式:.bz2
参数
-k 产生压缩文件后保留原文件
1
命令举例
#压缩
[root@localhost tmp]# bzip2 boduo
[root@localhost tmp]# bzip2 -k boduo
#解压
[root@localhost tmp]# bunzip2 boduo.bz2
gzip、gunzip 只能压缩文件不能压缩目录,而且删除源文件。硬伤呀,后缀是.gzzip、unzip 保留源文件,可以显示压缩比,参数-r可以压缩目录,后缀是.zip tar 我们俗称 tar包,只是将文件打包成.tar格式的,tar.gz则是,打包后再压缩,是两个过程。
最后说一下 bzip2格式,该格式是压缩比最大的压缩格式了,.bz2和.gz的区别在于,前者比后者压缩率更高,后者比前者花费更少的时间。也就是说同一个文件,压缩后,.bz2文件比.gz文件更小,但是.bz2文件的小是以花费更多的时间为代价的。