Skip to content

/errors/tar/gzip-stdin-not-in-gzip-format

gzip: stdin: not in gzip format / tar: Child returned status 1

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · tar (GNU tar) 1.35updated
tool
tar
exit code
2
versions
GNU tar 1.x
os
linux, macos, windows

gzip: stdin: not in gzip format followed by tar: Child returned status 1 means you asked tar to decompress with gzip (-z), and the file does not start with the gzip signature. Most often the file is a plain .tar, uses another compression (xz, bzip2, zstd), or is an HTML page saved by a failed download. Run file archive.tar.gz to see what it is, then extract with tar -xf archive.tar.gz: GNU tar detects the compression by itself when reading a file.

Reproduce it

bash
echo hello > a.txt
tar -cf archive.tar.gz a.txt
tar -xzf archive.tar.gz

Output · exit 2

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

The archive was created without compression, so gzip rejects it and tar exits with status 2.

Fix: let tar detect the format

bash
echo hello > a.txt
tar -cf plain.tar.gz a.txt
tar -cJf xz.tar.gz a.txt
for f in plain.tar.gz xz.tar.gz; do
  printf '%s: ' "$f"; head -c 6 "$f" | od -An -tx1 | tr -d '\n'; echo
  tar -tf "$f"
done

Output

plain.tar.gz:  61 2e 74 78 74 00
a.txt
xz.tar.gz:  fd 37 7a 58 5a 00
a.txt

tar -xf and tar -tf without -z, -j or -J recognise gzip, bzip2, xz, lzip, lzma, lzop and zstd archives by their first bytes. The first bytes tell the format:

First bytes (hex)Formattar option
1f 8bgzip-z
42 5a 68 (BZh)bzip2-j
fd 37 7a 58 5a 00xz-J
28 b5 2f fdzstd--zstd
3c (<)HTML or XML text, not an archivenone: re-download

A plain tar archive has no signature at the start; the ustar magic is at byte offset 257.

Downloads that are not archives

bash
curl -fL -o app.tar.gz https://example.org/app.tar.gz
file app.tar.gz

-L follows redirects (GitHub release links redirect) and -f makes curl fail on HTTP errors instead of saving the error page as app.tar.gz.

Reading from a pipe

When the archive comes from standard input (curl ... | tar -x), tar does not decompress it automatically; it names the option you need instead:

bash
echo hello > a.txt
tar -cJf xz.tar.gz a.txt
cat xz.tar.gz | tar -tf -
echo "exit status: ${PIPESTATUS[1]}"
cat xz.tar.gz | tar -tJf -

Output

tar: Archive is compressed. Use -J option
tar: Error is not recoverable: exiting now
exit status: 2
a.txt

Sources