Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux bzip2 Command

Linux bzip2 Command

Linux Command Reference Linux Command Reference

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 at compressing.

Syntax

bzip2 [options] [file...]

options common parameters:

Example

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 -k option:



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 use bunzip2 directly:



bzip2 -d example.txt.bz2

or



bunzip2 example.txt.bz2

This decompresses example.txt.bz2 back into the original example.txt file.

** Test compressed files**

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



bzip2 -t example.txt.bz2

If the file is intact and undamaged, the command produces no output; otherwise, it reports an error.

Linux Command Reference Linux Command Reference