Selected topic

Bzip2

Archiving And Compression

Prefer practical output? Use related tools below while reading.

What is bzip2?

bzip2 is a lossless data compression utility that uses the Burrows-Wheeler algorithm to compress files. It is designed to be fast and efficient, making it suitable for large files.

Key Features:

  • Lossless compression: bzip2 compresses files without losing any original data.
  • High compression ratio: bzip2 can achieve higher compression ratios than other lossless algorithms like gzip.
  • Fast compression and decompression: bzip2 is designed to be fast, making it suitable for large files.

Basic Usage:

The basic syntax of the bzip2 command is:
bash
bzip2 [options] file
Here are some common options:
  • -c: Compress or decompress from standard input/output.
  • -d: Decompress a file (inverse of compression).
  • -6, -7, etc.: Specify the compression level (1-9, where 1 is fastest and 9 is highest compression).

Example:

Let's say we want to compress a text file called example.txt using bzip2. We can use the following command:
bash
bzip2 -6 example.txt
This will create a new file called example.txt.bz2 that contains the compressed data.

To decompress the file, we can use the -d option:

bash
bzip2 -d example.txt.bz2

This will restore the original example.txt file from the compressed version.

Tips and Variations:


  • To compress multiple files at once, simply add more file names to the command.
  • To specify a different compression level (e.g., slower but higher compression), use the -6, -7, etc. options.
  • If you want to preserve the original file's timestamp and permissions, use the --preserve option.

I hope this summary helps! Let me know if you have any further questions or need more examples.