linux中xz是什么命令

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

linux中xz是什么命令

本教程操作环境:linux5.9.8系统、Dell G3电脑。

linux中xz是什么命令?

Linux系统中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

linux中xz是什么命令

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

xz -dk 20221119test2.txt.xz

linux中xz是什么命令

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

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

linux中xz是什么命令

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

linux中xz是什么命令

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

linux中xz是什么命令

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

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

相关推荐:《Linux视频教程

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享