tar shows "is not a bzip2 file" error when uncompressing a .tar.bz file

32,704

Solution 1

Your tarball is uncompressed. The extension .bz is obsolete and misleading.

You can decompress using the following command:

tar xvf data_or.tar.bz

What probably happened here is that data_or.tar.bz was created with the --auto-compress switch (or tar -cavf) that chooses the compression algorithm from the supplied extension.

The proper extension for bzip2 compressed files is .bz2, while the .bz extension is for bzip compressed files.

bzip uses arithmetic encoding (which is a patented algorithm), so bzip2 was created in 1997 as a patent-free alternative. As a result, bzip2 and bzip are incompatible.

tar cannot handle bzip (de)compression, so the --auto-compress switch resulted in an uncompressed tarball.

Solution 2

tar -xvjf file.tar.bz2 >> Because the flag 'j' is used, tar command will call bzip2 to process the decompression.

Reported error explained:

bzip2: (stdin) is not a bzip2 file. >> bzip2 reported to parent process (tar) that the received file to process is NOT bz2 format

tar: Child returned status 2 >> tar reports the error status received from bzip2 child process by exiting execution. In man documentation, error status means "2 to indicate a corrupt compressed file". As bzip2 did not recognized the format, it reports it as 'corrupt'

tar: Error is not recoverable: exiting now >> According to message received from child, compressed file is not accepted for processing

Steps to fixing the issue:

1- verify the format of the compression

file file.tar.bz2

POSIX tar archive (GNU) - "Or whatever other format", then correct it with the next step 2

2- tar -xvf file.tar.bz2 - "in case its a posix tar archive format"

Share:
32,704

Related videos on Youtube

Mithun Sreedharan
Author by

Mithun Sreedharan

Tweets @mithunp Works @QBurst

Updated on September 18, 2022

Comments

  • Mithun Sreedharan
    Mithun Sreedharan over 1 year

    I've a data_or.tar.bz file

    I tried to extract it with

    $ tar xjvf data_or.tar.bz

    Output is

    bzip2: (stdin) is not a bzip2 file.
    tar: Child returned status 2
    tar: Error is not recoverable: exiting now
    

    Can only bz2 files be extracted with tar command?

    -- update

    $ file data_or.tar.bz 
    data_or.tar.bz: POSIX tar archive (GNU)
    
    • bdecaf
      bdecaf over 12 years
      maybe it was wrongly named? if you feel lucky try tar xzvf ... or tar xvf ... - otherwise maybe a look into the head may reveal details.
    • Mokubai
      Mokubai over 12 years
      Try file data_or.tar.bz which should tell you if the file is simply a mis-named archive of a different type.
    • Mithun Sreedharan
      Mithun Sreedharan over 12 years
      @Mokubai [lease see updated question