Warning: Invalid argument supplied for foreach() in /home/techrecipes/public_html/wp-content/themes/techrecipes/header.php on line 77

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.

  • Halftrue_sierra

    where to put the command?

  • Sdsdfsd

     dull boy,
    in  the terminal

  • gbviswanadh

    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

  • saiful

    thanks for ur sugession

  • anuj

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

  • Linus

    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.

  • PM

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

  • mcng

    the terminal is a shell in gnome gibberish