xz in Linux is a command used to compress and decompress system files. After the compression is completed, the system will automatically add the ".xz" extension to the original file and delete the original file; the xz command can only Compress files, not directories.
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
What is the xz command in Linux?
Detailed explanation of xz command usage in Linux system (compression and decompression)
xz command: POSIX platform development has high Compression tool. It uses the LZMA2 compression algorithm, and the compressed files generated are smaller than the compressed files generated by gzip and bzip2 traditionally used by the POSIX platform, and the decompression speed is also very fast, compressing or decompressing xz files.
Function description:
xz command will compress and decompress system files. After the compression is completed, the system will automatically add the .xz extension to the original file and delete the original file. The xz command can only compress files, not directories.
Syntax structure:
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> (in English or Finnish). XZ Utils home page: <http:></http:></lasse.collin>
-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 # 显示版本号并退出
Compress a file 20221119test2.txt. After successful compression, 20221119test2.txt.xz will be generated. The original file will be deleted.
xz 20221119test2.txt
Decompress the 20221119test2.txt file and use the parameter -k to keep the original file from being deleted.
xz -dk 20221119test2.txt.xz
Use the parameter -l to display the basic information of the .xz file. Basic information includes compression rate, data integrity verification method, etc. It can also be used with the parameter -v or -vv to display more detailed information.
xz -l 20221119test2.txt.xz xz -lv 20221119test2.txt.xz
Use parameters -0, -1, -2, … -6, … -9 or parameters –fast, –best to set the compression rate. The default of the xz command is -6, and for most systems, even some older systems, the -4 ... -6 compression ratio presets work well.
Use the parameter -H to display all options of the xz command. The parameter -H is more detailed than the content displayed using the parameter -help.
Use the xargs command to compress multiple files in parallel. The following command line can compress all files with a .log extension in the /var/log directory. Run multiple xz at the same time for compression through the xargs command.
# 运行此命令须有 root 权限。 find /var/log -type f -iname "*.log" -print0 | xargs -P4 -n16 xz -T1
The above is the detailed content of What is the xz command in linux?. For more information, please follow other related articles on the PHP Chinese website!