LinuxCommandLibrary

lz4

Compress or decompress files, very quickly

TLDR

Compress a file

$ lz4 [path/to/file]
copy

Decompress a file
$ lz4 [[-d|--decompress]] [file.lz4]
copy

Decompress a file and write to stdout
$ lz4 [[-dc|--decompress --stdout]] [file.lz4]
copy

Package and compress a directory and its contents
$ tar cvf - [path/to/directory] | lz4 - [dir.tar.lz4]
copy

Decompress and unpack a directory and its contents
$ lz4 [[-dc|--decompress --stdout]] [dir.tar.lz4] | tar -xv
copy

Compress a file using the best compression
$ lz4 [[-12|--best]] [path/to/file]
copy

SYNOPSIS

lz4 [OPTIONS] [FILE...]
lz4 -d [OPTIONS] [FILE...]
unlz4 [OPTIONS] [FILE...]

PARAMETERS

-d, --decompress
    Decompress files.

-z, --compress
    Compress files (default action).

-f, --force
    Force overwrite of existing output files.

-k, --keep
    Do not delete source files after successful operation.

-1 to -12
    Set compression level (1 is fastest, 12 is high compression).

-l, --fast
    Alias for compression level 1 (fastest).

-BSIZE, --block-sizeSIZE
    Set frame block size (e.g., 4KB, 64KB, 256KB, 1MB, 4MB).

-V, --version
    Display version information.

-h, --help
    Display help message.

-q, --quiet
    Suppress all messages.

-v, --verbose
    Enable verbose output.

-c, --stdout, --to-stdout
    Write output to standard output, keep original files.

-r, --recursive
    Operate on files and directories recursively.

--rm-suffix
    Force removal of .lz4 suffix when decompressing.

--no-checksum
    Disable checksums for increased speed (not recommended for critical data).

DESCRIPTION

The lz4 command is a high-performance lossless data compression utility that leverages the LZ4 algorithm. It is primarily known for its incredibly fast compression and decompression speeds, often surpassing other common compressors like gzip or bzip2. This speed comes at the cost of a slightly lower compression ratio, making lz4 ideal for scenarios where throughput is more critical than absolute file size reduction.

Typical use cases include compressing large log files, speeding up backups, in-memory data compression, and real-time data processing. lz4 can operate on standard input/output, process specified files, and supports recursive operations on directories. It creates files with a .lz4 extension by default and can easily decompress them back to their original form.

CAVEATS

While exceptionally fast, lz4 generally provides a lower compression ratio compared to algorithms like gzip, bzip2, or xz. Users should choose lz4 when speed is the primary concern over maximum file size reduction. Also, content checksums are optional in the LZ4 stream format and might need to be explicitly enabled (or disabled) for enhanced data integrity or speed optimization respectively.

COMPRESSION LEVELS AND MODES

lz4 offers a range of compression levels (from -1 for fastest to -12 for higher compression ratio, albeit still very fast). It also supports different stream modes, including independent blocks for parallel processing and optional checksums for data integrity, which can be configured via specific options. These features allow users to fine-tune the balance between speed, compression, and data safety for diverse applications.

HISTORY

The LZ4 algorithm and the lz4 command-line utility were developed by Yann Collet, with the first public release occurring in 2011. It was designed from the ground up to prioritize extreme speed in both compression and decompression. Its high performance has led to widespread adoption across various industries and applications, including fast storage systems (like ZFS and Btrfs), databases (e.g., RocksDB, ClickHouse), and network communication protocols, making it a staple for high-throughput data processing.

SEE ALSO

gzip(1), bzip2(1), xz(1), tar(1)

Copied to clipboard