linux中xz命令怎么使用

82次阅读
没有评论

共计 2862 个字符,预计需要花费 8 分钟才能阅读完成。

今天丸趣 TV 小编给大家分享一下 linux 中 xz 命令怎么使用的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

linux 中 xz 是用于对系统文件进行压缩和解压缩的命令,压缩完成后,系统会自动在原文件后加上“.xz”的扩展名并删除原文件;xz 命令只能对文件进行压缩,不能对目录进行压缩。

xz 命令:POSIX 平台开发具有高压缩率的工具。它使用 LZMA2 压缩算法,生成的压缩文件比 POSIX 平台传统使用的 gzip、bzip2 生成的压缩文件更小,而且解压缩速度也很快,压缩或解压缩 xz 文件。

功能说明:

xz 命令会对系统文件进行压缩和解压缩,压缩完成后,系统会自动在原文件后加上.xz 的扩展名并删除原文件。xz 命令只能对文件进行压缩,不能对目录进行压缩。

语法结构:

xz(选项)(参数)
xz [OPTION]... [FILE]...

xz --help
Usage: xz [OPTION]... [FILE]...
Compress or decompress FILEs in the .xz format.
 -z, --compress force compression
 -d, --decompress, --uncompress
 force decompression
 -t, --test test compressed file integrity
 -l, --list list information about .xz files
 -k, --keep keep (don t delete) input files
 -f, --force force overwrite of output file and (de)compress links
 -c, --stdout, --to-stdout
 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!
 -e, --extreme try to improve compression ratio by using more CPU time;
 does not affect decompressor memory requirements
 -T, --threads=NUM use at most NUM threads; the default is 1; set to 0
 to use as many threads as there are processor cores
 -q, --quiet suppress warnings; specify twice to suppress errors too
 -v, --verbose be verbose; specify twice for even more verbose
 -h, --help display this short help and exit
 -H, --long-help display the long help (lists also the advanced options)
 -V, --version display the version number and exit
With no FILE, or when FILE is -, read standard input.
Report bugs to  lasse.collin@tukaani.org  (in English or Finnish).
XZ Utils home page:  http://tukaani.org/xz/
 -z, --compress #  强制压缩
 -d, --decompress, --uncompress
 # force decompression
 -t, --test #  测试压缩文件的完整性
 -l, --list #  列出有关.xz 文件的信息
 -k, --keep #  保留(不要删除)输入文件
 -f, --force #  强制覆盖输出文件和(解)压缩链接
 -c, --stdout, --to-stdout
 #  写入标准输出,不要删除输入文件
 -0 ... -9 #  压缩预设;  默认为 6;  取压缩机 * 和 *
 #  使用 7 - 9 之前解压缩内存使用量考虑在内! -e, --extreme #  尝试通过使用更多的 CPU 时间来提高压缩比;
 #  要求不影响解压缩存储器
 -T, --threads=NUM #  最多使用 NUM 个线程;  默认值为 1; set to 0
 #  设置为 0,使用与处理器内核一样多的线程
 -q, --quiet #  抑制警告;  指定两次以抑制错误
 -v, --verbose #  冗长;  指定两次更详细
 -h, --help #  显示这个简洁的帮助并退出
 -H, --long-help #  显示更多帮助(还列出了高级选项) -V, --version #  显示版本号并退出 

压缩一个文件 20221119test2.txt,压缩成功后生成 20221119test2.txt.xz, 原文件会被删除。

xz 20221119test2.txt

解压 20221119test2.txt 文件,并使用参数 -k 保持原文件不被删除。

xz -dk 20221119test2.txt.xz

使用参数 -l 显示 .xz 文件的基本信息。基本信息包括压缩率、数据完整性验证方式等。也可以和参数 -v 或 -vv 配合显示更详尽的信息。

xz -l 20221119test2.txt.xz
xz -lv 20221119test2.txt.xz

使用参数 -0, -1, -2, … -6, … -9 或参数 –fast, –best 设定压缩率。xz 命令的默认为 -6,对于大多数系统来说,甚至是一些较旧的系统,-4 … -6 压缩率预设值都不错的表现。

使用参数 -H 显示 xz 命令所有 options. 参数 -H 比使用参数 –help 显示的内容更详细。

借助 xargs 命令并行压缩多文件。下面的命令行可以将 /var/log 目录下所有的扩展名为 .log 的文件压缩。通过 xargs 命令同时运行多个 xz 进行压缩。

# 运行此命令须有 root 权限。
find /var/log -type f -iname *.log -print0 | xargs -P4 -n16 xz -T1

以上就是“linux 中 xz 命令怎么使用”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,丸趣 TV 小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注丸趣 TV 行业资讯频道。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-12发表,共计2862字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)