0% found this document useful (0 votes)
40 views

Linux Bzip2 Command Tutorial For Beginners

This document discusses the Linux bzip2 command line utility for compressing and decompressing files. It provides 6 examples of common bzip2 commands: 1) how to compress a single file, 2) compress multiple files, 3) decompress a file, 4) compress without deleting the original, 5) display compression details, and 6) check the integrity of a compressed file. The tutorial concludes by encouraging the reader to practice the examples and learn more about bzip2's additional options from its manual page.

Uploaded by

ZAIDAN DIDI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Linux Bzip2 Command Tutorial For Beginners

This document discusses the Linux bzip2 command line utility for compressing and decompressing files. It provides 6 examples of common bzip2 commands: 1) how to compress a single file, 2) compress multiple files, 3) decompress a file, 4) compress without deleting the original, 5) display compression details, and 6) check the integrity of a compressed file. The tutorial concludes by encouraging the reader to practice the examples and learn more about bzip2's additional options from its manual page.

Uploaded by

ZAIDAN DIDI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Linux bzip2 Command Tutorial for Beginners

(6 Examples)

On this page

1. Linux bzip2 command


2. Q1. How to compress a file using bzip2?
3. Q2. How to compress multiple files using bzip2?
4. Q3. How to decompress using bzip2?
5. Q4. How to make bzip2 not delete input file?
6. Q5. How to make bzip2 display details for each compression operation?
7. Q6. How to check integrity of a compressed file?
8. Conclusion
File compressions are carried out according to specific algorithms. There are many
compression techniques, and one of them is achieved through bzip2. In this tutorial,
we will learn the basics of bzip2 using some easy to understand examples. Please
note that all examples used in this article have been tested on an Ubuntu 18.04LTS
machine.
Linux bzip2 command
bzip2 is a command line based file compressor in Linux that uses the Burrows-
Wheeler block sorting text compression algorithm and Huffman coding to carry out
the compression process. Following is its syntax:

bzip2 [OPTIONS] filenames ...

Q1. How to compress a file using bzip2?


Basic usage is very simple - just pass the file to be compressed as input to the bzip2
command. Here's is an example:

bzip2 list.txt

The following screenshot shows the command in action:

Q2. How to compress multiple files using bzip2?


Simple - just pass the filenames as input. See the following example:

bzip2 list.txt list1.txt list2.txt


Q3. How to decompress using bzip2?
For decompression, use the -d command line option. Here's an example:

bzip2 -d list.txt.bz2

Q4. How to make bzip2 not delete input file?


By default, when bzip2 compresses a file, it deletes the original (or input) file.
However, if you don't want that to happen, use the -k command line option.
Following is an example:

Q5. How to make bzip2 display details for each


compression operation?
This can be done using the -v command line option. Here's how the man page
explains it:
-v --verbose
Verbose mode -- show the compression ratio for each file pro
cessed. Further -v's
increase the verbosity level, spewing out lots of information
which is primarily of
interest for diagnostic purposes.

Following is an example that shows bzip2 command output when -v is used:

Q6. How to check integrity of a compressed file?


The bzip2 command can also be used to check the integrity of a .bz2 file (a test that
makes sure the file isn't corrupt or has changed since it was created). This can be
done using the -t command line option.
-t --test
Check integrity of the specified file(s), but don't decompress them.
This really performs a trial decompression and throws away the result.

Conclusion
The bzip2 command line utility offers many more options, but whatever we have
discussed here should be enough to get you started. Once you're done practicing the
options we've discussed in this tutorial, you can head to the tool's man page to learn
more about it

You might also like