LinuxCommandLibrary

lrzip

Compress files for high ratio and speed

TLDR

Compress a file with LZMA - slow compression, fast decompression

$ lrzip [path/to/file]
copy

Compress a file with BZIP2 - good middle ground for compression/speed
$ lrzip -b [path/to/file]
copy

Compress with ZPAQ - extreme compression, but very slow
$ lrzip -z [path/to/file]
copy

Compress with LZO - light compression, extremely fast decompression
$ lrzip -l [path/to/file]
copy

Compress a file and password protect/encrypt it
$ lrzip -e [path/to/file]
copy

Override the number of processor threads to use
$ lrzip -p [8] [path/to/file]
copy

SYNOPSIS

lrzip [options] [files...]
lrzip -d [options] [files...]
lrzip -t [options] [files...]
lrzip -l [options] [files...]

PARAMETERS

-z, --compress
    Compress the specified files. This is the default action.

-d, --decompress
    Decompress the specified files.

-t, --test
    Test the integrity of the compressed files without decompressing them.

-l, --list
    List the contents (e.g., uncompressed size, compression ratio) of the compressed files.

-o <file>, --output <file>
    Specify the output file name instead of the default.

-L <level>, --level <level>
    Set the compression level, where 1 is fastest/least compression and 9 is slowest/most compression. A level of 0 implies the best compression.

-C <algo>, --compress-alg <algo>
    Specify the compression algorithm to use (e.g., LZMA, BZIP2, GZIP, LZO, LZ4, ZSTD, BROTLI). Default is LZMA.

-m <MB>, --memory <MB>
    Set the maximum memory usage for compression in megabytes. Higher values can improve compression ratio but require more RAM.

-p <threads>, --threads <threads>
    Use the specified number of CPU threads for compression or decompression.

-U, --unlink
    Delete the source file after successful compression or decompression.

--sparse
    Handle sparse files efficiently, preserving sparse regions and reducing output size.

--recursive
    Operate on files within directories recursively. Note: This compresses each file individually, not the directory structure into a single archive.

--exclude <pattern>
    Exclude files matching the specified pattern from compression.

--check
    Perform an integrity check (CRC or MD5) after compression to ensure data validity.

-q, --quiet
    Suppress all warnings and messages during operation.

-v, --verbose
    Display more information during operation, such as progress and statistics.

-h, --help
    Display a help message and exit.

-V, --version
    Display version information and exit.

DESCRIPTION

lrzip is a highly efficient compressor designed to achieve extremely high compression ratios, especially on large files. It leverages multiple compression algorithms, primarily LZMA for its core compression engine, combined with an LZP preprocessor and optional Bzip2, Gzip, LZO, LZ4, ZSTD, or Brotli filters. This multi-algorithm approach, along with its ability to utilize multiple CPU cores and large memory pages, allows lrzip to deliver superior compression performance and speed, particularly for data that is difficult for other compressors to handle. It's often chosen for archiving large datasets, backups, and any scenario where maximizing disk space savings is paramount, without sacrificing decompression speed significantly.

CAVEATS

While lrzip excels at high compression, particularly on large files, achieving the highest compression ratios often requires significant memory. Users should monitor memory usage, especially with the --best or higher --level options. Additionally, lrzip is a file compressor, not a general-purpose archiving tool like tar. It does not natively preserve file permissions, ownership, or directory structures within a single archive. For full directory archiving, it's typically combined with tar (e.g.,
tar -cf - dir | lrzip > archive.lrz). The --recursive option compresses individual files within directories, not the directory as a whole.

WORKING WITH DIRECTORIES

lrzip operates primarily on individual files. While the --recursive option allows it to process files within directories, it compresses each file separately rather than bundling them into a single archive file (like a .tar.lrz). To archive entire directories with their structure, permissions, and ownership, lrzip is commonly piped with tar. For example, to create an archive of a directory:
tar -cf - mydir | lrzip -o mydir.tar.lrz
To extract a tar.lrz archive:
lrzunzip -o - mydir.tar.lrz | tar -xf -

COMPRESSION ALGORITHMS AND MEMORY

lrzip supports a range of compression algorithms, controllable via the --compress-alg (-C) option. The default and generally most effective is LZMA, often combined with an LZP preprocessor. Other supported algorithms include BZIP2, GZIP, LZO, LZ4, ZSTD, and Brotli, each offering different trade-offs between compression ratio and speed. Higher compression levels (-L 0 or --best) and larger dictionary sizes significantly increase memory requirements during compression. For example, compressing a large file with default LZMA settings might require hundreds of megabytes or even gigabytes of RAM depending on the file size and desired compression. Decompression, however, typically uses much less memory, making lrzip suitable for distribution where decompression speed and memory usage are critical.

HISTORY

lrzip was developed by Con Kolivas, a well-known Linux kernel developer famous for his work on CPU schedulers (e.g., BFS). The project emerged from a desire to create a compressor that specifically targeted large files, offering superior compression ratios and performance compared to existing tools like gzip and bzip2, especially when combined with high-memory systems. Its design emphasizes speed during decompression and efficient use of system resources for very high compression, continuing the legacy of his earlier rzip project.

SEE ALSO

lrzcat(1), lrzunzip(1), tar(1), gzip(1), bzip2(1), xz(1), zstd(1), lz4(1)

Copied to clipboard