Extract a bz2 or bzip2 file

Home -> UNIX

11956 views

From the computer of: qmchenry (338 recipes)
Created: Jul 11, 2006


Add a comment

Add to:
Add to stumbleuponAdd to del.icio.usDigg itAdd to FURL

You've downloaded a file that ends in .bz2. Now what do you do? This 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

bzip2 -d file.bz2


This will 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 like

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:

bzip2 -dc file2.bz2 | grep tech-recipes

Subscribe to the Tech-Recipes Newsletter

You can get tips like this delivered in your email every week!

Enter your Email

We will never, ever sell your email address or spam you.





Related recipes:

  Decompress and extract a tgz or tar.gz archive in a single step
  Extract a tar archive or file
  Select an arbitrary column of text in UNIX
  Tar and compress a file in one step
  Extract a gzip compressed tar archive in Linux
  Checkout files from CVS
  Search for text in binary files
  Loop over a set of files from the shell
  Ubuntu: 4 Ways to Install Programs or Packages
  UNIX: Shortcut to create a backup copy of a file

 

Sponsored links

 

Login

Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.