您的位置:首页 > 运维架构 > Linux

linux 各压缩工具

2016-03-09 23:04 344 查看
压缩工具有:zip、gzip 、bzip2、xz
归档工具有:tar、cpio

一、压缩工具
******zip
1、压缩
[root@node3 tmp]# zip messages.gz messages
adding: messages (deflated 86%)
[root@node3 tmp]# ls -l
total 420
-rw------- 1 root root 376011 Mar 26 23:14 messages
-rw-r--r-- 1 root root  52512 Mar 26 23:15 messages.gz
2、解压
[root@node3 tmp]# unzip messages.gz
zip还可以对目录进行压缩但必须使用文件名通配其目录下的所有文件,默认不会打包目录下所有文件的。
[root@node3 tmp]# zip etc.gz /etc   \\对目录错误的压缩方法
adding: etc/ (stored 0%)
[root@node3 tmp]# zip etc.gz /etc/*   \\ 正确的压缩方法需使用文件名通配目录下所有的文件
注意:虽然使用通配来指定目录下所有的文件,但目录下子目录中的文件依然不会被打包压缩

******gzip
zca:查看压缩包内容
后缀:gz
常用选项
-d 解压
-c 将压缩结果送往标准输出,可以使用重定向将其保存为压缩文件,从而保留原文件
1、压缩,压缩后不会保留原文件。
[root@node3 tmp]# ls -lh messages
-rw------- 1 root root 368K Mar 26 23:14 messages
[root@node3 tmp]# gzip messages
[root@node3 tmp]# ls -lh messages.gz
-rw------- 1 root root 52K Mar 26 23:14 messages.gz
2、解压,解压后不会保留原文件。
# gunzip messages.gz

# gzip -d messages.gz
3、不解压压缩包直接查看内容
# zcat messages.gz
4、默认压缩后不会保留其原文件,如需要可以使用如下方法。
# gzip -c messages > messages.gz


******bzip2
bzcat 查看压缩包内容
后缀:.bz2
1、压缩
[root@node3 tmp]# bzip2 messages
[root@node3 tmp]# ls -l
total 24
-rw-r--r-- 1 root root 22094 Mar 26 23:38 messages.bz2
2、解压
# bzip2 -d messages.bz2

# bunzip2  messages.bz2


*****xz
xzcat:查看压缩包内容
后缀:.xz
1、压缩
[root@node3 tmp]# xz messages
[root@node3 tmp]# ls -l
total 20
-rw-r--r-- 1 root root 17508 Mar 26 23:38 messages.xz
2、解压
# xz -d messages.xz

# unxz messages.xz


注意:以上打包工具都支持压缩比,使用 "- #",#号取值范围为1-9 ,默认为6.压缩工具只能对文件进行压缩不能对目录进行压缩,对目录进行压缩需要使用tar工具。

二、归档工具
tar

tar [options] -f file.tar File1 ...
选项
-c:创建归档
-x:展开归档
-t:不展开而直接查看被归档的文件
-C:指定压缩的目录

-z:调用gzip压缩,后缀gz
-j:调用bzip2工具压缩,后缀为bz2
-J:调用xz工具压缩,后缀为xz

1、只对/etc目录进行打包
# tar cf etc.tar etc
2、打包etc目录并使用gzip工具进行压缩
[root@node3 tmp]# tar -zcf etc.tar.gz etc
[root@node3 tmp]# ls
etc  etc.tar.gz  messages
3、解压,可以不指定使用哪个压缩工具。
# tar xf etc.tar.gz
4、指定解压到指定的目录
[root@node3 tmp]# tar xf etc.tar.gz -C /tmp/mem
[root@node3 tmp]# ls /tmp/mem
etc


本文出自 “菜鸟日志” 博客,请务必保留此出处http://zkxfoo.blog.51cto.com/1605971/1749359
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: