POSIX platform development tools with high compression rates
xz command XZ Utils is a tool developed for POSIX platform with high compression rate. It uses the LZMA2 compression algorithm, and the compressed files generated are smaller than those generated by gzip and bzip2 traditionally used by the POSIX platform, and the decompression speed is also very fast. Initially, XZ Utils was developed based on LZMA-SDK, but LZMA-SDK included some features of the WINDOWS platform, so XZ Utils was significantly modified to adapt to the POSIX platform. The emergence of XZ Utils is also to replace the old LZMA Utils in POSIX systems.
xz(option)(parameter)
xz [OPTION]... [FILE]...
-z, --compress # Force compression
-d, --decompress, --uncompress
# force decompression
-t, --test # Test the integrity of the compressed file
-l, --list # List information about .xz files
-k, --keep # Keep (do not delete) input files
-f, --force # Force overwriting of output files and (de)compression links
-c, --stdout, --to-stdout
# Write to standard output, do not delete input files
-0 ... -9 # Compression preset; default is 6; take compressor * and *
# Decompression memory usage before using 7-9 is taken into account!
-e, --extreme # Attempt to increase compression ratio by using more CPU time;
# Requires no impact on decompressed memory
-T, --threads=NUM # Use up to NUM threads; default value is 1; set to 0
# Set to 0 to use as many threads as processor cores
-q, --quiet # Suppress warnings; specify twice to suppress errors
-v, --verbose # Verbose; specify twice for more verbosity
-h, --help # Display this concise help and exit
-H, --long-help # Show more help (advanced options are also listed)
-V, --version # Display version number and exit
Compress a file test.txt. After successful compression, test.txt.xz is generated. The original file will be deleted.
$ xz test.txt
$ ls test.txt*
test.txt.xz
Unzip the test.txt.xz file and use the parameter -k to keep the original file from being deleted
$ xz -d -k test.txt.xz
$ ls test.txt*
test.txt.xz test.txt
Use the parameter -l to display basic information about 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 index.txt.xz
#Strms Blocks Compressed Uncompressed Ratio Check Filename
# 1 1 768 B 1,240 B 0.619 CRC64 index.txt.
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, -4 ... -6 compression ratio presets work well.
$ xz -k7 xz_pipe_decomp_mini.c
$ xz -k --fast xz_pipe_decomp_mini.c
Use the -H parameter to display all options for the xz command. The -H parameter is more verbose than the --help parameter.
$ xz -H | more
Compress multiple files in parallel with the help of xargs command. 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.
# You must have root permissions to run this command.
find /var/log -type f -iname "*.log" -print0 | xargs -P4 -n16 xz -T1