LZ4(1)
๐ LZ4 โ bestie edition ๐
okay so. hi. you're here because you wanna compress or decompress .lz4 files, and you want the tea on how lz4 works. this is the manual page for lz4 from the LZ4(1) family of User Commands, and we are going through it together, no skips, no skimming, periodt. โจ
๐ NAME ๐
lz4 โ and also unlz4, and also lz4cat โ compress or decompress .lz4 files. that's the whole vibe.
๐ฆ SYNOPSIS ๐ฆ
lz4 [OPTIONS] [-|INPUT-FILE] OUTPUT-FILE
unlz4 is equivalent to lz4 -d
lz4cat is equivalent to lz4 -dcfm
bestie listen up: when you're writing scripts that need to decompress files, it is recommended to always use the namelz4with appropriate arguments (lz4 -dorlz4 -dc) instead of the namesunlz4andlz4cat. like, just do it that way, okay? ๐ซถ
โจ DESCRIPTION โจ
lz4 is a CLI based on liblz4, an extremely fast implementation of a lossless compression algorithm. it provides a default compression speed of typically > 500 MB/s per core, which is genuinely giving main character energy. ๐
speed can be traded for a higher compression ratio by increasing the compression level parameter. while decompression is single-threaded, it reaches multiple GB/s, generally fast enough to be I/O bound. the lz4 native file format is the .lz4 format.
๐ธ Difference between lz4 and gzip ๐ธ
lz4 supports a command line syntax similar but not identical to gzip(1). the differences are:
lz4compresses a single file by default (see-mfor multiple files)lz4 file1 file2means : compressfile1intofile2lz4 file.lz4will default to decompression (use-zto force compression)lz4preserves original files (see--rmto erase source file on completion)lz4shows real-time notification statistics during compression or decompression of a single file (use-qto silence them)- when no destination is specified, result is sent on implicit output, which depends on stdout status. when stdout is Not the console, it becomes the implicit output. otherwise, if stdout is the console, the implicit output is
filename.lz4. - it is considered bad practice to rely on implicit output in scripts, because the script's environment may change. always use explicit output in scripts.
-censures that output will be stdout. conversely, providing a destination name, or using-mensures that the output will be either the specified name, orfilename.lz4respectively.
default behaviors can be modified by opt-in commands, detailed below.
lz4 -mmakes it possible to provide multiple input filenames, which will be compressed into files using suffix.lz4. progress notifications become disabled by default (use-vto enable them). this mode has a behavior which more closely mimicsgzipcommand line, with the main remaining difference being that source files are preserved by default.- similarly,
lz4 -m -dcan decompress multiple*.lz4files. - it's possible to opt-in to erase source files on successful compression or decompression, using
--rmcommand. - consequently,
lz4 -m --rmfeatures a behavior closer to thegzipone.
๐ง Concatenation of .lz4 files ๐ง
it is possible to concatenate .lz4 files as is. lz4 will decompress such files as if they were a single .lz4 file. for example:
lz4 file1 > foo.lz4
lz4 file2 >> foo.lz4
then lz4cat foo.lz4 is equivalent to cat file1 file2. iconic, obsessed, no notes. ๐ซถ
๐ OPTIONS ๐
๐ Short commands concatenation ๐
in some cases, some options can be expressed using short command -x or long command --long-word. short commands can be concatenated together. for example, -d -c is equivalent to -dc. long commands cannot be concatenated. they must be clearly separated by a space.
๐ Multiple commands ๐
when multiple contradictory commands are issued on a same command line, only the latest one will be applied. (last one wins, bestie. survival of the fittest fr fr.)
๐ Operation mode ๐
-z,--compressโ compress. this is the default operation mode when no operation mode option is specified, no other operation mode is implied from the command name (for example,unlz4implies--decompress), nor from the input file name (for example, a file extension.lz4implies--decompressby default).-zcan also be used to force compression of an already compressed.lz4file.-d,--decompress,--uncompressโ decompress.--decompressis also the default operation when the input filename has an.lz4extension.-t,--testโ test the integrity of compressed.lz4files. the decompressed data is discarded. no files are created nor removed.-b#โ benchmark mode, using#compression level.--listโ list information about.lz4files. for detailed information on files with multiple frames, use-v.--listautomatically triggers-mmodifier.
๐ Operation modifiers ๐
-#โ compression level, with#being any value from1to12. higher values trade compression speed for compression ratio. values above12are considered the same as12. recommended values are1for fast compression (default), and9for high compression. the speed/compression trade-off will vary depending on data to compress. decompression speed remains fast at all settings.--fast[=#]โ switch to ultra-fast compression levels. the higher the value, the faster the compression speed, at the cost of some compression ratio. if=#is not present, it defaults to1. this setting overrides compression level if one was set previously. similarly, if a compression level is set after--fast, it overrides it.--bestโ set highest compression level. same as-12.-T#,--threads=#โ use#threads for compression. when0, or none provided: automatically determined from nb of detected cores.--favor-decSpeedโ generate compressed data optimized for decompression speed. compressed data will be larger as a consequence (typically by~0.5%), while decompression speed will be improved by5-20%, depending on use cases. this option only works in combination with very high compression levels (>=10).-DdictionaryName โ compress, decompress or benchmark using dictionary dictionaryName. compression and decompression must use the same dictionary to be compatible. using a different dictionary during decompression will either abort due to decompression error, or generate a checksum error.-f,--[no-]forceโ this option has several effects:- if the target file already exists, overwrite it without prompting.
- when used with
--decompressandlz4cannot recognize the type of the source file, copy the source file as is to standard output. this allowslz4cat --forceto be used likecat (1)for files that have not been compressed withlz4.
-c,--stdout,--to-stdoutโ force write to standard output, even if it is the console.-m,--multipleโ multiple input files. compressed file names will be appended a.lz4suffix. this mode also reduces notification level. can also be used to list multiple files.lz4 -mhas a behavior equivalent togzip -k(it preserves source files by default).-rโ operate recursively on directories. this mode also sets-m(multiple input files).-B#โ block size[4-7](default :7)-B4=64KB;-B5=256KB;-B6=1MB;-B7=4MB
-BIโ produce independent blocks (default)-BDโ blocks depend on predecessors (improves compression ratio, more noticeable on small blocks)-BXโ generate block checksums (default:disabled)--[no-]frame-crcโ select frame checksum (default:enabled)--no-crcโ disable both frame and block checksums--[no-]content-sizeโ header includes original size (default:not present)- note : this option can only be activated when the original size can be determined, hence for a file. it won't work with unknown source size, such as stdin or pipe.
--[no-]sparseโ sparse mode support (default:enabled on file, disabled on stdout)-lโ use Legacy format (typically for Linux Kernel compression)- note :
-lis not compatible with-m(--multiple) nor-r
- note :
๐ Other options ๐
-v,--verboseโ verbose mode-q,--quietโ suppress warnings and real-time statistics; specify twice to suppress errors too-h,-H,--helpโ display help/long help and exit-V,--versionโ display Version number and exit-k,--keepโ preserve source files (default behavior)--rmโ delete source files on successful compression or decompression--โ treat all subsequent arguments as files
๐ Benchmark mode ๐
-b#โ benchmark file(s), using#compression level-e#โ benchmark multiple compression levels, fromb#toe#(included)-i#โ minimum evaluation time in seconds[1-9](default :3)
๐ Environment Variables ๐
it's possible to pass some parameters to lz4 via environment variables. this can be useful in situations where lz4 is known to be invoked (from a script for example) but there is no way to pass lz4 parameters to influence the compression session. the environment variable has higher priority than executable default, but lower priority than corresponding runtime command. when set as global environment variables, it can be a way to enforce personalized defaults different from the executable set ones.
LZ4_CLEVELโ specify a default compression level thatlz4employs for compression when no other compression level is specified on command line. executable default is generally1.LZ4_NBWORKERSโ specify a default number of threads thatlz4will employ for compression. executable default is generally0, which means auto-determined based on local cpu. this functionality is only relevant whenlz4is compiled with multithreading support. the maximum number of workers is capped atLZ4_NBWORKERS_MAX(200by default).
๐ BUGS ๐
report bugs at: https://github.com/lz4/lz4/issues
๐ AUTHOR ๐
Yann Collet
and that's the whole page, bestie. this was lz4 version 1.10.0, dated July 2024. go forth and compress something gorgeous. bye bye, ilysm ๐ฆ๐โจ
๐ฆ where this page comes from
- alpine 3.22: lz4-doc 1.10.0-r0 ยท BSD-2-Clause AND GPL-2.0-or-later
- alpine 3.23: lz4-doc 1.10.0-r0 ยท BSD-2-Clause AND GPL-2.0-or-later
- alpine 3.24: lz4-doc 1.10.0-r1 ยท BSD-2-Clause AND GPL-2.0-or-later
- debian trixie: lz4 1.10.0-4 ยท GPL-2.0-or-later
- fedora 43: lz4 1.10.0-3.fc43 ยท GPL-2.0-or-later AND BSD-2-Clause
- fedora 44: lz4 1.10.0-4.fc44 ยท GPL-2.0-or-later AND BSD-2-Clause
- nixpkgs unstable: lz4 1.10.0
- opensuse-leap 16.0: lz4 1.10.0-160000.3.1 ยท BSD-2-Clause AND GPL-2.0-or-later
- opensuse-leap 16.0: lz4 1.10.0-160000.3.1 ยท BSD-2-Clause AND GPL-2.0-or-later
- opensuse-leap 16.0: lz4 1.10.0-160000.3.1 ยท BSD-2-Clause AND GPL-2.0-or-later
- opensuse-leap 16.0: lz4 1.10.0-160000.3.1 ยท BSD-2-Clause AND GPL-2.0-or-later
- ubuntu questing: lz4 1.10.0-4build1
- ubuntu resolute: lz4 1.10.0-8 ยท GPL-2.0-or-later
- ubuntu stonking: lz4 1.10.0-10 ยท GPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms