Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I untar a tar.bz file in unix?

I've found tons of pages saying how to untar tar.bz2 files, but how would one untar a tar.bz file?

like image 304
Tim Avatar asked Feb 26 '12 16:02

Tim


People also ask

Which command to extract data tar in Unix?

The most common uses of the tar command are to create and extract a tar archive. To extract an archive, use the tar -xf command followed by the archive name, and to create a new one use tar -czf followed by the archive name and the files and directories you want to add to the archive.

How do I untar a tar bz file?

To extract (unzip) a tar. bz2 file simply right-click the file you want to extract and select “Extract”. Windows users will need a tool named 7zip to extract tar.

What is Z in tar command?

z – filter archive through gzip. r – append or update files or directories to the existing archive files. W – Verify an archive file. wildcards – Specify patterns in UNIX tar command.


3 Answers

use the -j option of tar.

tar -xjf /path/to/archive.tar.bz
like image 122
Shiplu Mokaddim Avatar answered Oct 17 '22 22:10

Shiplu Mokaddim


According to the man pages for bzip2

   If  the  file  does  not end in one of the recognised endings, .bz2, .bz, .tbz2 or .tbz, bzip2 complains that it cannot guess the
   name of the original file, and uses the original name with .out appended.

Based on this, I'm guessing that '.bz' is considered a valid suffix for bzip2 compressed files. Also, keep in mind that the original file name was probably generated by hand, something like this:

tar jcf archive.tar.bz /path/to/files

Rather than doing this:

tar cf archive.tar /path/to/files && bzip2 archive.tar

Which would force the filename to be archive.tar.bz2.

Unless the file that you're unpacking is older than, say 1998 (bzip2 was released in 1996), I'm guessing that you're actually looking at a bz2 file.

If you're interested in the history of bzip vs bzip2 and the technical differences between the two, there's good discussion on the Wikipedia Bzip2 page as well as the archive of the bzip2 home page. The latter includes a link to the original bzip source, which is not compatible with bzip2 because the it would require patent encumbered code to de-compress files compressed with the original bzip.

The file types differ by magic number, bzip2 uses BZh, the original bzip uses BZ0.

like image 29
Barton Chittenden Avatar answered Oct 17 '22 22:10

Barton Chittenden


If it's really an old bzip 1 archive, try:

bunzip archive.tar.bz

and you'll have a standard tar file. Otherwise, it's the same as with .tar.bz2 files.

like image 3
Michele Spagnuolo Avatar answered Oct 17 '22 21:10

Michele Spagnuolo