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

 

About Quinn McHenry

Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

8 Responses to “Extract a bz2 or bzip2 File”

  1. August 09, 2010 at 6:19 am, Halftrue_sierra said:

    where to put the command?

    Reply

  2. July 01, 2011 at 2:29 pm, Sdsdfsd said:

     dull boy,
    in  the terminal

    Reply

  3. September 18, 2011 at 4:41 am, gbviswanadh said:

    file are in ***.zip.bz2 , is this possible in linux os to unzip a file at time, is there any command is there or not

    Reply

  4. September 14, 2012 at 4:28 pm, saiful said:

    thanks for ur sugession

    Reply

  5. October 23, 2012 at 2:57 pm, anuj said:

    what is a terminal and where do i put the command in

    Reply

  6. December 17, 2012 at 3:51 am, Linus said:

    What is this? Amateur hour?

    @Halftrue_sierra: Notice that it says “UNIX” at the top of this page? When you’re in UNIX-land, there is only one place you can put that command – in the commandline.

    @gbvishawnadh: Are you saying that your file is compressed using zip and then compressed again using bzip2? If so, you can try bzip2 -d filename.zip.bz2 | unzip

    @anuj: Terminal is the red colored thing on your car’s battery.

    Reply

  7. December 31, 2012 at 2:40 am, PM said:

    How do I uncompress the compressed archived to a specific directory?

    Reply

  8. September 13, 2013 at 5:34 am, mcng said:

    the terminal is a shell in gnome gibberish

    Reply

Leave a Reply