Linux中常用的压缩打包工具和常用命令

Linux中目前常用的压缩工具有gzip,bzip2和xz,打包工具有tar。

gzip:全称GNUzip,属于GNU自由软件,用于UNⅨ系统的文件压缩,由Jean-loup Gailly和Mark Adler创建,在1993年2月发布了1.0版本。GZIP压缩文件后生成后缀为.gz的文件。很多WEB站点通过GZIP压缩技术减小传输数据包的大小,提高网站访问速度。

bzip2:是一个基于Burrows-Wheeler变换的无损压缩软件,能够把普通的数据文件压缩10%至15%,是一款免费软件,可以自由分发免费使用,压缩后生成后缀为.bz2的压缩文件。

xz:XZ Utils使用 LZMA2 压缩算法,压缩率比gzip和bzip2高,压缩后生成后缀为.xz的压缩文件。

tar:是Unix和类Unix系统上的打包工具,可以将多个文件合并为一个文件,属于GNU自由软件,最初的设计目的是将文件备份到磁带上(tape archive),因而得名tar,打包后生成.tar的文件。

安装命令
gzip:

[root@root /]#yum -y install gzip

安装完成后查询版本信息:

[root@root /]#gzip -V
gzip 1.5
Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
Copyright (C) 1993 Jean-loup Gailly.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License .
There is NO WARRANTY, to the extent permitted by law.

Written by Jean-loup Gailly.

bzip2:

[root@root /]#yum -y install bzip2

安装完成后查询版本信息:

[root@root /]# bzip2 -V
bzip2, a block-sorting file compressor.  Version 1.0.6, 6-Sept-2010.
   
   Copyright (C) 1996-2010 by Julian Seward.
   
   This program is free software; you can redistribute it and/or modify
   it under the terms set out in the LICENSE file, which is included
   in the bzip2-1.0.6 source distribution.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   LICENSE file for more details.
   
bzip2: I won't write compressed data to a terminal.
bzip2: For help, type: `bzip2 --help'.

xz:

[root@root /]#yum -y install xz

安装完成后查询版本信息:

[root@root /]# xz -V
xz (XZ Utils) 5.2.2
liblzma 5.2.2

压缩命令
tar结合gzip打包压缩

tar -zcvf report.tar.gz *.pdf

tar结合bzip2打包压缩

tar -jcvf report.tar.bz2 *.pdf

tar结合xz打包压缩

tar -Jcvf report.tar.xz *.pdf
[root@pingtai2 creditReport]# ll
total 38952
-rw-r--r-- 1 root root 14456880 Aug 20 15:46 report.tar.bz2
-rw-r--r-- 1 root root 14725049 Aug 20 15:44 report.tar.gz
-rw-r--r-- 1 root root 10700128 Aug 20 15:50 report.tar.xz

通过压缩后文件的大小可以看出xz的压缩率比较高

解压命令
解压gzip压缩的文件

tar -zxvf report.tar.gz

解压bzip2压缩的文件

tar -jxvf report.tar.bz2

解压xz压缩的文件

tar -Jxvf report.tar.xz

-z:打包后使用gzip压缩
-j:打包后使用bzip2压缩
-J:打包后使用xz压缩
-c:建立压缩档案
-x:解压
-v:显示所有过程
-f:指定要处理的文件名

你可能感兴趣的:(IT运维,gzip,bzip2,xz,tar)