lz4(1)
LZ4 is an extremely fast lossless compression algorithm and command-line tool for compressing and decompressing files.
Synopsis
lz4 [OPTION]... [FILE]...Description
lz4 is a block-sorting compression codec emphasizing speed over compression ratio. It compresses data very quickly and decompresses even faster, making it ideal for scenarios where compression speed matters more than achieving maximum compression. The tool can read from stdin and write to stdout, enabling use in pipelines.
By default, lz4 compresses files by appending the .lz4 extension and removes the original. Decompression reverses this process, stripping the .lz4 extension to recreate the original filename. Multiple files can be compressed or decompressed in a single command.
Common options
| Flag | What it does |
|---|---|
-d, --decompress | decompress files (automatically detected if filename ends in .lz4) |
-z, --compress | force compression mode (default) |
-c, --stdout | write compressed stream to stdout; do not modify original files |
-k, --keep | preserve input files after compression/decompression |
-f, --force | overwrite output files without prompting |
-1 to -12 | compression level; 1=fast, 12=high ratio (default 9) |
-m, --multiple | operate on multiple consecutive frames (default for stdin) |
-v, --verbose | verbose output; print processed filename and sizes |
-q, --quiet | suppress informational messages and warnings |
-h, --help | display help message and exit |
-V, --version | display version information and exit |
Examples
compress myfile.txt to myfile.txt.lz4; original file is deleted
lz4 myfile.txtcompress myfile.txt to myfile.txt.lz4 but keep the original file
lz4 -k myfile.txtdecompress myfile.txt.lz4 back to myfile.txt
lz4 -d myfile.txt.lz4compress data from stdin to stdout, saving to a file without modifying the original
cat largefile.bin | lz4 -c > largefile.bin.lz4fast compression of tarball on-the-fly for remote transfer and extraction
lz4 -1 -c myfile.txt | ssh user@host 'lz4 -d -c | tar x'compress all .txt files in current directory with verbose output showing progress
lz4 -v *.txtcompress with maximum compression level (slower), overwriting any existing output
lz4 -12 -f sensitive.dbdecompress multiple concatenated lz4 frames from a single file to stdout
lz4 -d -m concatenated.lz4 > output.bin