$linuxjunkies
>

lz4(1)

LZ4 is an extremely fast lossless compression algorithm and command-line tool for compressing and decompressing files.

UbuntuDebianFedoraArch

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

FlagWhat it does
-d, --decompressdecompress files (automatically detected if filename ends in .lz4)
-z, --compressforce compression mode (default)
-c, --stdoutwrite compressed stream to stdout; do not modify original files
-k, --keeppreserve input files after compression/decompression
-f, --forceoverwrite output files without prompting
-1 to -12compression level; 1=fast, 12=high ratio (default 9)
-m, --multipleoperate on multiple consecutive frames (default for stdin)
-v, --verboseverbose output; print processed filename and sizes
-q, --quietsuppress informational messages and warnings
-h, --helpdisplay help message and exit
-V, --versiondisplay version information and exit

Examples

compress myfile.txt to myfile.txt.lz4; original file is deleted

lz4 myfile.txt

compress myfile.txt to myfile.txt.lz4 but keep the original file

lz4 -k myfile.txt

decompress myfile.txt.lz4 back to myfile.txt

lz4 -d myfile.txt.lz4

compress data from stdin to stdout, saving to a file without modifying the original

cat largefile.bin | lz4 -c > largefile.bin.lz4

fast 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 *.txt

compress with maximum compression level (slower), overwriting any existing output

lz4 -12 -f sensitive.db

decompress multiple concatenated lz4 frames from a single file to stdout

lz4 -d -m concatenated.lz4 > output.bin

Related commands