Linux Comm Bzip2
# Linux bzip2 Command
[ Linux Command Manual](#)
The Linux bzip2 command is used to compress files.
Similar to gzip, bzip2 provides better compression ratios by using a more efficient compression algorithm (Burrows-Wheeler algorithm), but the compression speed is usually slightly slower.
### Syntax
bzip2 [file...]
* `file...`: The file(s) to compress. `bzip2` will compress the specified file(s), generate a compressed file with a `.bz2` suffix, and delete the original file(s).
**Common options**:
* `-d`: Decompress a `.bz2` file. Equivalent to using the `bunzip2` command.
* `-k`: Keep the original file, do not delete it.
* `-v`: Display detailed compression or decompression process.
* `-z`: Force compression even if the file is already compressed.
* `-t`: Test the integrity of the compressed file.
* `-1` to `-9`: Specify the compression ratio. `-1` is the fastest compression with the lowest compression ratio; `-9` is the slowest compression with the highest compression ratio. The default is `-9`.
### Examples
**Compress a file**
bzip2 example.txt
This command will compress `example.txt` into `example.txt.bz2` and delete 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 will keep the original `example.txt` file and generate `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` back to the original `example.txt` file.
**Test a compressed file**
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 not corrupted, this command will produce no output; otherwise, it will prompt an error.
[ Linux Command Manual](#)
AI is thinking...
[](#)(#)
(#)[](#)
[Byte Ark Coding Plan supports major large language models like Doubao, GLM, DeepSeek, Kimi, MiniMax, etc., with official supply and stable reliability. Configuration Guide Β₯9.9/month Activate Now](https://maas.xfyun.cn/modelSquare?ch=maas_lm_l2E)
### Click me to share notes
YouTip