FreeKB - Linux Commands bunzip2 (unzip a bzip2 archive)
Linux Commands - bunzip2 (unzip a bzip2 archive)

The bunzip2 command can be used to uuncompress a bzip2 compressed file. Let's take an example where the /home/john.doe directory contains a bzip2 compressed file.

[john.doe@server1 ~]# ls -l /home/john.doe
-rw-r--r-- john.doe john.doe 12345 Jan 01 :17:16 example.file.bz2


The bunzip2 command can be used to decompress example.file.bz2.

[john.doe@server1 ~]# bunzip2 /home/john.doe/example.file.bz2


Display the contents of the compressed file

The -c or --stdout option can be used to view the contents of a bzip2 compressed file. In this example, the contents of example.file.bz2 are displayed.

[john.doe@server1 ~]# bunzip2 -c /home/john.doe/example.file.bz2
Hello World


Keep the compressed file

By default, bunzip2 will remove the bzip2 compressed file, creating a new decompressed file. The -k or --keep option can be used to save the original file, and also create a new uncompressed file.

[john.doe@server1 ~]# bunzip2 -k /home/john.doe/example.file.bz2


In this example, the original uncompressed file is kept, and a new compressed file is also created.

[john.doe@server1 ~]# ls -l /home/john.doe
-rw-r--r-- john.doe john.doe 12345 Jan 01 :17:16 example.file
-rw-r--r-- john.doe john.doe  1012 Jan 01 :17:16 example.file.bz2



The -l or --list option can be used to view statistics of a compressed gzip file. The -l option will display the size of the uncompressed file, the size of the compressed file, the compression percentage, and the name of the uncompressed file.

[john.doe@server1 ~]# gunzip -l /home/john.doe/example.file.gz
compressed  uncompressed  ratio  uncompressed_name
        52           672  96.9%       example.file


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter c3939 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |