Learn how to shrink files reliably with bzip2 and when to choose its options. 24.02.2026 | reading time: 3 min bzip2 is a command-line compressor that yields strong compression for single files and streams; learn how to compress, inspect and restore files with a few decisive commands. Shrink a log file now Start by compressing a file: run `bzip2 -v server.log` and you will see a short report such as `server.log: 62.4% -- replaced with server.log.bz2` and the original `server.log` is removed; to keep the original use `bzip2 -k server.log` and to decompress use `bunzip2 server.log.bz2` or `bzip2 -d server.log.bz2`. Peek without extracting Pipe compressed data to commands: `bzcat server.log.bz2 | head -n 20` shows the first lines without creating a file, and `bzip2 -c file > file.bz2` writes compressed bytes to stdout so you can chain compressors or send output over SSH. Archive with tar Combine bzip2 with tar for directories: create an archive with `tar -cjf archive.tar.bz2 mydir/` and extract with `tar -xjf archive.tar.bz2`; this keeps timestamps and permissions intact while producing better compression than gzip in many cases. Tune compression and memory Adjust `-1` through `-9` to trade speed versus size (`-1` fastest, `-9` best compression) and remember that higher settings use more memory because block size grows from 100k to 900k, so pick a level suitable for your machine or use streamed compress with `-1` on low-memory systems. Safety and testing Use `bzip2 -t file.bz2` to verify integrity without decompression and add `-v` for verbose progress; use `-f` to overwrite existing files when automating and consider keeping originals with `-k` during risky operations. When parallel speed matters For multi-core machines, swap in `pbzip2` or `lbzip2` which speak the same file format but compress in parallel, giving much faster runtimes on large datasets while remaining compatible with standard `bunzip2` for decompression. Compare and pick bzip2 often beats gzip on size but lags in speed; xz can compress smaller but at greater CPU and memory cost, so choose bzip2 when you want a middle ground and widespread compatibility. Clear next step Try compressing a directory and testing the archive on another machine to validate your workflow; mastering these commands is practical and quick to verify, and it sharpens real system administration skills. Join Bits & Bytes Academy First class LINUX exam preparation. utilities storage backup scripting