Linux XZ压缩格式学习
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux XZ压缩格式学习相关的知识,希望对你有一定的参考价值。
XZ的介绍
今天升级Python的时候,下载的Python-2.7.8.tar.xz安装包为xz格式,好吧,我又孤陋寡闻了,居然第一次遇见xz格式的压缩文件。搜索了一下资料,下面是xz的一些介绍:
xz是一个使用 LZMA压缩算法的无损数据压缩文件格式。和gzip与bzip2一样,同样支持多文件压缩,但是约定不能将多于一个的目标文件压缩进同一个档案文件。相反,xz通常作为一种归档文件自身的压缩格式,例如使用tar或cpioUnix程序创建的归档。xz 在GNU coreutils(版本 7.1 或更新)中被使用。xz 作为压缩软件包被收录在 Fedora (自Fedora 12起), Arch Linux, FreeBSD、 Slackware Linux、CRUX 和 Funtoo中。
XZ Utils压缩代码的核心是基于LZMA SDK,但它已经被修改了很多以适应XZ Utils。主压缩算法目前是LZMA2,它在.xz容器格式中使用。 使用典型文件,XZ Utils比gzip创建的输出比gzip小30%,比bzip2小15%。到目前为止,lzma utils 的压缩率仍是最大的,XZ Utils 解压时间占优势。
XZ Utils的官方网站为:http://tukaani.org/xz/ ,官网关于XZ的介绍资料如下:
XZ Utils
XZ Utils is free general-purpose data compression software with a high compression ratio. XZ Utils were written for POSIX-like systems, but also work on some not-so-POSIX systems. XZ Utils are the successor to LZMA Utils.
The core of the XZ Utils compression code is based on LZMA SDK, but it has been modified quite a lot to be suitable for XZ Utils. The primary compression algorithm is currently LZMA2, which is used inside the .xz container format. With typical files, XZ Utils create 30 % smaller output than gzip and 15 % smaller output than bzip2.
XZ Utils consist of several components:
· liblzma is a compression library with an API similar to that of zlib.
· xz is a command line tool with syntax similar to that of gzip.
· xzdec is a decompression-only tool smaller than the full-featured xz tool.
· A set of shell scripts (xzgrep, xzdiff, etc.) have been adapted from gzip to ease viewing, grepping, and comparing compressed files.
· Emulation of command line tools of LZMA Utils eases transition from LZMA Utils to XZ Utils.
While liblzma has a zlib-like API, liblzma doesn\'t include any file I/O functions. A separate I/O library is planned, which would abstract handling of .gz, .bz2, and .xz files with an easy to use API.
XZ的安装
从官方网址下载https://tukaani.org/xz/xz-5.2.3.tar.gz后,安装非常简单。如果你可以yum安装,那么就更简单。有些版本甚至默认就自带xz压缩命令。
tar -xzvf xz-5.2.3.tar.gz
cd xz-5.2.3
./configure
make
make install
XZ的使用
-z | force compression | 压缩文件 |
-d | force decompression | 解压文件 |
-t | test compressed file integrity | 测试压缩文件完整性 |
-l | list information about .xz files | 列出压缩文件.xz的一些信息 |
-k | keep (don\'t delete) input files | 保留被解压缩的文件 |
-f | force overwrite of output file and (de)compress links | 强制覆盖输出文件和(de)压缩链接 |
-c | write to standard output and don\'t delete input files | 压缩输入标准输出并保留被压缩的文件。 |
-0 … -9 | compression preset; default is 6; take compressor *and* decompressor memory usage into account before using 7-9! | 压缩率预设参数 -0 到 -9调节压缩率。如果不设置,默认压缩等级是6 |
-e | try to improve compression ratio by using more CPU time; does not affect decompressor memory requirements | 尝试通过使用更多的CPU时间来提高压缩比; 不影响解压内存的要求 |
-T | use at most NUM threads; the default is 1; set to 0 to use as many threads as there are processor cores | 压缩的线程数量。默认为1,设置为0表示跟处理器核数匹配 |
-q | suppress warnings; specify twice to suppress errors too | 抑制警告 指定两次以抑制错误 |
-v | be verbose; specify twice for even more verbose | 显示压缩、解压详细信息 |
-H | display the long help (lists also the advanced options) | 显示更多的帮助信息,包含告警选项。 |
-V | 以上是关于Linux XZ压缩格式学习的主要内容,如果未能解决你的问题,请参考以下文章 |