bzip2 Linux Commands

What is Linux bzip2 Command?

Explanation

bzip2 COMMAND:

bzip2 linux command is used to compress the file. Each file is replaced by a compressed version of itself with .bz2 extension.

SYNTAX :


bzip2 [ options ] filenames

OPTIONS:


- c Compress or decompress to standard output.
- d Force decompression.
- z The complement to -d. Force compression.
- t Performs the integrity test. It performs a trial decompression test and prints the result.
- f Force overwrite of output file.
- k Keep the original file. dont delete the input file during compression or decompression.
- q Quiet, suppress non-essential warning messages.
- s Reduce memory usage, for compression,decompression and testing.
- v verbose mode shows the compression ratio for each file processed.
- V Displays the version of the software.
- L Displays the license terms and conditions.
- 1 Performs fast compression,creating a relatively large files.
- 9 Get the best possible compression.

EXAMPLE:


  1. To Compress a file using bzip2:
    Lets have a text file as an example.
    $ ls -l -rw-rw-r-- 1 hiox hiox 9150000 Sep 26 18:37 hiox.txt $ bzip2 -c -1 hiox.txt > hiox.txt.bz2 $ ls -l -rw-rw-r-- 1 hiox hiox 9150000 Sep 26 18:37 hiox.txt -rw-rw-r-- 1 hiox hiox
    17706 Sep 27 12:38 hiox.txt.bz2

    From the above example it is clear that the filesize is reduced from 9150000 bytes to 17706.
    When the File is reduced with option -9 the filesize still gets reduced.
    $ bzip2 -c -9 hiox.txt > hscripts.txt.bz2 $ ls -l -rw-rw-r-- 1 hiox hiox 9150000 Sep 26 18:37 hiox.txt -rw-rw-r-- 1 hiox hiox
    17706 Sep 27 12:38 hiox.txt.bz2 -rw-rw-r-- 1 hiox hiox
    2394 Sep 27 13:01 hscripts.txt.bz2

    When the file is compressed with -1 the size was 17706 bytes and now the filesize is 2394 bytes. The 9 makes best compression but the default is 6.

Ask Questions

Ask Question