Home·Terminal commands

bzip2

Archives

Usage

bzip2 [-k] <file>

Squeezes harder than gzip but takes longer, and like gzip it deletes the original and leaves only the .bz2 unless you pass `-k`; the tar flag for it is `-j`, and decompressing is `-d`, which is what bunzip2 does.

Common flags

FlagMeaning
-kKeep the original, which it otherwise deletes.
-dDecompress; bunzip2 is the same thing.
-cWrite to stdout.
-1 / -9Block size from 100k to 900k. -9 is the default.
-tTest integrity.

Examples

bzip2 -k bigfile.log

Compress but keep the original.

bzip2 -dc data.bz2 | wc -l

Count lines without unpacking to disk.

tar -cjf logs.tar.bz2 ./logs

The tar flag for bzip2 is -j.

Bundling and compressing are separate jobs: tar bundles, gzip shrinks, and .tar.gz is both.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does bzip2 do?

Squeezes harder than gzip but takes longer, and like gzip it deletes the original and leaves only the .bz2 unless you pass `-k`; the tar flag for it is `-j`, and decompressing is `-d`, which is what bunzip2 does.

Q. How do I type it?

bzip2 [-k] <file> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

5 are listed here; the full set is in man bzip2. This command sits under Archives.

Related commands

man page: man bzip2