bzip2 command in Linux with Examples

bzip2 command in Linux is used to compress and decompress the files i.e. it helps in binding the files into a single file which takes less storage space as the original file use to take. It has a slower decompression time and higher memory use. It uses Burrows-Wheeler block sorting text compression algorithm, and Huffman Coding. Each file is replaced by a compressed version of itself, with the name original name of the file followed by extension bz2.

Syntax:

bzip2 [OPTIONS] filenames ...

Options:

  • -z : This option forces compression. It is an opposite command of decompression i.e. -d Option.
    $ bzip2 -z input.txt

    Example:

    Note: This option deletes the orignal file also.

  • -k: This option does compression but does not deletes the original file.
    $ bzip2 -k input.txt

    Example:

  • -d : This option is used for decompression of compressed files.
    $ bzip2 -d input.txt.bz2

    Example:

  • -t : This option does the integrity check of the file and does not decompresses the file. It gives us the idea that the file is corrupt or not.
    $ bzip2 -t input.txt.bz2

    Example:

  • -v : Verbose mode show the compression ratio for each file processed. It also increases the verbosity level, spewing out lots of information which is primarily of interest for diagnostic purposes.
    $ bzip2 -v input.txt

    Example:

  • -h –help : To display the help message and exit.
  • -L –license -V –version : It is used to display the software version, license terms, and conditions.
  • -q –quiet : It will suppress non-essential warning messages. Messages pertaining to I/O errors and other critical events will not be suppressed.
  • -f –force : It will force overwrite of output files.


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.