Linux bzip2 Command

Linux 命令大全Complete Linux Commands

The Linux bzip2 command is used to compress files.

Similar to gzip, bzip2 provides a better compression ratio by using a more efficient compression algorithm (Burrows-Wheeler algorithm), but is usually slightly slower.

Syntax

bzip2 [options] [file...]
  • file...: The file to be compressed.bzip2Compresses the specified file and generates a.bz2compressed file with a suffix, while deleting the original file.

options common parameters:

  • -d: Decompress a.bz2file. Equivalent to using thebunzip2command.
  • -k: Keep the original file, do not delete it.
  • -v: Display detailed compression or decompression process.
  • -z: Force compression even if the file has already been compressed.
  • -t: Test the integrity of the compressed file.
  • -1to-9: Specify the compression ratio.-1is the fastest compression with the lowest compression ratio;-9is the slowest compression with the highest compression ratio. The default is-9。

Examples

Compress a file

bzip2 example.txt

This command compresses example.txt into example.txt.bz2 and deletes the original file example.txt.

Keep the original file

If you want to keep the original file after compression, you can use the-koption:

bzip2 -k example.txt

This command keeps the original example.txt file and generates example.txt.bz2.

Decompress a file

To decompress a .bz2 file, you can use the -d option or directly use bunzip2:

bzip2 -d example.txt.bz2

or

bunzip2 example.txt.bz2

This will decompress example.txt.bz2 into the original example.txt file.

Test compressed file

You can use the -t option to test the integrity of the compressed file:

bzip2 -t example.txt.bz2

If the file is complete and undamaged, the command will produce no output; otherwise, it will report an error.

Linux 命令大全Complete Linux Commands

Other extensions