How to Fix ‘tar: Child returned status 2’ and ‘tar: Error is not recoverable’ in Linux

Extracting compressed archives in Linux using the tar command only to be halted by the error: ‘gzip: stdin: unexpected end of file’, ‘tar: Child returned status 2’, and ‘tar: Error is not recoverable: exiting now’ terminates decompression. In Unix and Linux systems, tar (Tape Archive) acts as an archiver that spawns child decompression processes (such as gzip, bzip2, or xz) to handle file inflation. Error status 2 indicates that the child decompression binary failed critically due to an archive format mismatch, premature file truncation during download, or corrupted byte blocks.

Why Does tar Report ‘Child returned status 2’?

When you pass compression flags (such as -z or -j) to tar, it pipes raw archive data through an external decompressor. Triggers for status 2 include:

  • Mismatched Compression Flags: Passing the gzip flag (-z) on a file compressed with bzip2 (.bz2), xz (.xz), or zstandard (.zst).
  • Incomplete or Truncated Download: Network dropouts during wget or curl downloads causing the archive file to cut off before the end-of-file (EOF) marker.
  • Corrupted File Transmission: Bit flips or damaged sectors in downloaded archives failing cryptographic cyclic redundancy checks (CRC).
  • Exhausted Disk Space: The destination partition running out of free bytes or inodes while unpacking archive contents.
  • Incorrect File Extension: A web server serving an HTML error page or raw uncompressed tar file while naming it archive.tar.gz.

Step 1: Determine the True File Compression Type

Do not rely on the file extension alone. Use the file command to inspect the archive’s internal magic bytes.

  1. In your Linux terminal, inspect the file type:
    file archive.tar.gz
  2. Review the output:
    • gzip compressed data: Use tar -xvzf archive.tar.gz
    • bzip2 compressed data: Use tar -xvjf archive.tar.gz
    • XZ compressed data: Use tar -xvJf archive.tar.gz
    • Zstandard compressed data: Use tar --zstd -xvf archive.tar.gz
    • HTML document / ASCII text: The file is an error page (e.g. 404 or Cloudflare gate) downloaded instead of the true archive.
    • POSIX tar archive: The file is uncompressed; extract it using tar -xvf archive.tar.gz without compression flags.

Step 2: Test Archive Integrity and Check for Truncation

Verify whether the archive suffered data corruption or premature truncation during transit.

  1. For .gz archives, test the gzip stream integrity using gunzip -t:
    gunzip -t archive.tar.gz
  2. If the output returns ‘unexpected end of file’ or ‘invalid compressed data’, the download was truncated.
  3. Re-download the file verifying the complete content length:
    curl -C - -O https://example.com/archive.tar.gz
  4. If provided by the vendor, verify the checksum:
    sha256sum archive.tar.gz

Step 3: Let tar Auto-Detect the Compression Format

Modern implementations of GNU tar (version 1.22 and later) can detect compression algorithms automatically, removing human error from flag selection.

  1. Run the extraction command using only the generic -xf options:
    tar -xvf archive.tar.gz
  2. GNU tar will read the magic bytes at the beginning of the file and invoke the appropriate child decompressor automatically.

Step 4: Recover Intact Files from a Damaged Archive

If the archive is partially corrupt but you need to salvage intact files stored before the corrupted sector:

  1. Use the -i (ignore zero blocks) flag to instruct tar to continue past corrupted blocks:
    tar -xvif archive.tar.gz
  2. Alternatively, decompress the outer gzip wrapper first while allowing partial recovery:
    zcat archive.tar.gz | tar -xvf - --ignore-failed-read

Step 5: Verify Destination Disk Capacity and Inodes

Ensure that the target directory has sufficient storage blocks and inodes to unpack the archive.

  1. Check free disk space:
    df -h .
  2. Check free inodes:
    df -i .

Verifying magic file types, testing archive integrity with gunzip, and relying on tar automatic compression detection eliminates Child returned status 2 errors in Linux.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.