Tutorial-9122023

Linux bzip2 Command Tutorial for Beginners (6 Examples)

bzip2 basic

Linux bzip2 Command Tutorial for Beginners (6 Examples)

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 22.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 ...

And here is what the man page says about this tool: bzip2  compresses  files  using  the Burrows-Wheeler block sorting text
       compression algorithm, and Huffman coding.   Compression  is  generally
       considerably   better   than   that   achieved   by  more  conventional
       LZ77/LZ78-based compressors, and approaches the performance of the  PPM
       family of statistical compressors.

       The  command-line options are deliberately very similar to those of GNU
       gzip, but they are not identical.

       bzip2 expects a list of file names to accompany the command-line flags.
       Each  file is replaced by a compressed version of itself, with the name
       "original_name.bz2".  Each compressed file has  the  same  modification
       date,  permissions,  and, when possible, ownership as the corresponding
       original, so that these properties can be correctly restored at  decom?
       pression  time.  File name handling is naive in the sense that there is
       no mechanism for preserving original file  names,  permissions,  owner?
       ships  or dates in filesystems which lack these concepts, or have seri?
       ous file name length restrictions, such as MS-DOS.

Following are some Q&A-styled examples that should give you a good idea on how the bzip2 command works.

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:

About Himanshu Arora

Himanshu Arora has been working on Linux since 2007. He carries professional experience in system level programming, networking protocols, and command line. In addition to HowtoForge, Himanshu’s work has also been featured in some of world’s other leading publications including Computerworld, IBM DeveloperWorks, and Linux Journal.

Share this page:

svg%3E
svg%3E
svg%3E
svg%3E

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !