
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
Statistics
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
Did you find this article helpful?
If so, consider buying me a coffee over at