How to Fix ‘tar: Child Returned Status 2’ Error in Linux

Extracting a compressed archive in Linux only for the command to terminate with the error: “tar: Child returned status 2” followed by “tar: Error is not recoverable: exiting now” prevents software installation and file recovery. In Unix-like operating systems, tar (Tape Archive) bundles files together while delegating decompression to child utilities like gzip, bzip2, or xz based on command flags. When an archive download is truncated, an incorrect decompression flag is provided (such as using -z for a bzip2 archive), or storage disk space is exhausted, the child compression process exits with error code 2. This tutorial outlines how to identify true archive compression formats, verify file integrity, and extract archives cleanly in Linux.

Why Does tar Throw Child Returned Status 2?

The parent tar process spawns a sub-shell child process to handle decompression. Common causes of exit code 2 include:

  • Corrupted or Incomplete File Download: Network disconnections leaving an archive truncated before the EOF marker.
  • Mismatched Compression Flags: Providing -z (gzip) for an archive compressed with xz or bzip2.
  • HTML File Saved as Archive: wget or curl downloading an HTTP 404/403 HTML error page instead of the actual binary file.
  • Disk Space or Inode Exhaustion: Insufficient space in the destination partition to extract the archive contents.
  • Permission Restrictions: Attempting to extract files into a root-protected directory without elevated permissions.

Method 1: Identify the True File Type Using ‘file’

Never rely solely on the file extension; inspect the binary magic bytes using the Linux file command.

file archive-name.tar.gz

Observe the output carefully:

  • If the output says HTML document text: Your download failed and you downloaded a 404 web page. Re-download the file with curl -L to follow redirects.
  • If the output says bzip2 compressed data: Use -j instead of -z:
    tar -xjf archive-name.tar.gz
  • If the output says XZ compressed data: Use -J:
    tar -xJf archive-name.tar.gz
  • If the output says gzip compressed data: Proceed to Method 2 to test archive integrity.

Method 2: Test Archive Integrity Directly via Child Utilities

Running the child decompressor with a test flag pinpoints whether the archive file contains corrupted blocks.

For Gzip archives (.tar.gz / .tgz):

gzip -t archive-name.tar.gz

If this returns “unexpected end of file” or “invalid compressed data–crc error”, the file is physically truncated and must be downloaded again.

For Bzip2 archives (.tar.bz2):

bzip2 -t archive-name.tar.bz2

Method 3: Let Modern tar Detect Compression Automatically

Modern GNU tar versions automatically detect the compression algorithm based on magic bytes; omitting manual compression flags avoids human syntax errors.

tar -xvf archive-name.tar.gz

By using -xf without specifying z, j, or J, GNU tar inspects the header automatically and delegates decompression to the correct engine.

Method 4: Check Destination Disk Space and Inodes

Verify that your destination filesystem has both adequate gigabytes and available filesystem inodes:

df -h .
df -i .

If free space or inode usage is at 100%, delete unneeded files or extract the archive to an alternate mount point.

Get the best tech tips delivered straight to your inbox.

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