Board logo

标题: 使用 XZ Utils 获得更高的压缩率-关于 XZ 指令 [打印本页]

作者: look_w    时间: 2018-1-10 11:15     标题: 使用 XZ Utils 获得更高的压缩率-关于 XZ 指令

使用 xz 命令xz 命令的基本用法复杂的用法从上面执行结果来看,利用合适的 filter Chain 最终生成的文件大小为 865KB。参数 --x86 --lzma2 就组成了一个 filter Chain。参数 --x86 是指使用 x86 平台的 BCJ filter,适用于 32 位和 64 位系统。参数 --lzma2 则指使用 lzma2 算法进行压缩。
使用 xzgrep,xzcat,xzdiff 等实用工具xzcatxzcat 命令其相当于 "xz --decompress --stdout" 就是将解压出的数据输出到标准输出 (stdout)。下面的例子用来统计压缩 test.txt.xz 文件所包含数据的行数。
1
$ xzcat test.txt.xz | wc -l  ## count the lines of test.txt




xzgrepxzgrep 可以用来 grep 压缩文件所包含的数据内容。其内部就是调用 grep 命令,所以参数和 grep 一致。下面的例子打印出 xz_pipe_comp_mini.c.xz 中所有包含以"lzma_"开头单词的行号和行内容。例:
1
2
3
4
5
6
7
$ xzgrep -P -n "lzma_\w+" xz_pipe_comp_mini.c.xz
8:    lzma_check check = LZMA_CHECK_CRC64;
9:    lzma_stream strm = LZMA_STREAM_INIT; /* alloc and init lzma_stream struct */
15:    lzma_easy_encoder (&strm, 6, LZMA_CHECK_CRC64);
28:        lzma_action action = in_finished ? LZMA_FINISH : LZMA_RUN;
35:            lzma_code (&strm, action); /* compress data */
42:     lzma_end (&strm);




xzless 和 xzmore这两个命令可以分页查看压缩文件中的内容。简单的来说,相当于
1
"xzcat <file.xz> | less" 或 "xzcat <file.xz> | more"




xzdiff 和 xzcmp这两个命令用于比较两个 .xz 文件。内部分别调用命令 diff 和 cmp 来实现文件内容的比较。例:
1
2
3
4
5
6
7
8
$ xzdiff xz_pipe_comp_mini.c.orig.xz xz_pipe_comp_mini.c.xz
20c20
<         if (feof (in_file))
---
>         if (feof (in_file))  {
21a22
>         }
$






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0