Extract a bz2 or bzip2 File
You have downloaded a file that ends in .bz2. Now, what do you do? This tech-recipe describes how to work with these files.
A file with an extension of bz2 has been compressed with the bzip2 program. Programs like bzip2 and gzip work on a single file, so they are not themselves an archive of multiple files like a zip archive can be.
To extract the file file.bz2, use the following:
bzip2 -d file.bz2
This will produce an uncompressed file in the current directory called “file” and will delete the original bz2 archive. If you want to keep the original file, add the -k option as follows:
bzip2 -dk file.bz2
A useful option for bzip2 is the -c switch which causes bzip2 to write the uncompressed output to stdout which can easily be redirected to another option. For instance, to search the compressed file file.bz2 for the string tech-recipes, use the following:
bzip2 -dc file2.bz2 | grep tech-recipes
Follow the reactions below and share your own thoughts.