Quick fix
# One-liner: inspect the archive structure first, then strip one top-level layer (GNU tar / Linux / WSL)
tar -tzf pkg.tar.gz | head && mkdir -p out && tar -xzf pkg.tar.gz -C out --strip-components=1
What you will run into
After extracting a tar.gz, the directory structure doesn't match expectations: plain tar -xzf pkg.tar.gz adds a pkg/ prefix; on macOS, trying to remove it with --strip-components reports Option --strip-components is not supported.
Open-source packages commonly carry one top-level directory, so extracting directly adds a layer or scatters files into wrong places.
Why this happens
Member paths in the tar archive include the top-level directory prefix from packaging time; tar -xzf restores paths verbatim and won't "smartly" drop the outer directory;
--strip-components=N is exactly for this: stripping the first N path components during extraction.
Two common confusion points:
| Confusion point | Notes |
|---|---|
| GNU tar vs BSD tar | GNU tar (built into Linux/WSL) supports --strip-components; BSD tar (built into macOS) doesn't, only -s substitution expressions |
| Wrong strip count | When N exceeds the actual path depth, members are silently skipped (no error, no files) — harder to spot than "an extra layer" |
Member paths inside a tar archive are the full relative paths recorded at packaging time;
extraction restores them verbatim and never "smartly" drops the outer directory — --strip-components=N is the explicit instruction: strip the first N path components during extraction.
Two common confusions: GNU tar (Linux/WSL built-in) supports --strip-components; BSD tar (macOS built-in) does not (use -s substitution expressions);
an N that is too large makes members skip silently (no error, files just do not appear) — harder to spot than "one extra directory level" because it looks like a successful extraction.
Deterministic takeaway: if the extracted tree is nested wrong, inspect the real member paths with tar -tf <archive> | head, count the levels, then pick N; "unknown option" on macOS = BSD tar — use -s or install GNU tar; "extracted but files missing" = N too large, decrease it;
fixed diagnostic: look at the path structure with -tf first, then set N — never guess.
Step by step
1. Inspect the structure before extracting — Diagnose
tar -tzf pkg.tar.gz
Count how many top-level directory layers there are.
2. Strip one top-level layer — Required
mkdir -p out
tar -xzf pkg.tar.gz -C out --strip-components=1
Specify a target directory to avoid scattering into the current dir.
3. macOS (BSD tar) alternative — Advanced
brew install gnu-tar
gtar -xzf pkg.tar.gz --strip-components=1
Or extract to a temp dir and mv pkg/* . (good enough for simple cases).
4. When unsure about the strip count — Required
tar -tzf first to see paths, then decide N; right after stripping, find/ls to confirm files actually came out — over-stripping never errors; "files missing" is the only result.
5. In scripts — Required
Fix the extract step as tar -xzf <pkg> -C <dir> --strip-components=1 and then verify key files exist, not just the exit code.
How to confirm it works
Extraction lands in the right place (measured output shape):
--strip-components=1 extract → out2/a.txt, out2/b.txt (prefix stripped, measured)
Counter-example: --strip-components=2 (exceeds depth) → exit 0 but zero files extracted (measured confirmed)Other environments
| Environment | Notes |
|---|---|
| GNU tar (Linux/WSL) | Supports --strip-components (measured tar 1.35) |
| macOS BSD tar | Reports "Option not supported" (SO #60486284); install gnu-tar or use mv |
| Over-stripping | Silent skip, no error (measured) |
| Target directory | Use -C to avoid scattering |
| Scripts | Verify key files exist; don't trust only the exit code |
Symptom
Extracted files end up in the wrong place:
# Expected files in the current dir, got an extra wrapper directory instead
$ tar -xzf pkg.tar.gz
$ find . -type f
./pkg/a.txt
./pkg/b.txt # unwanted pkg/ prefix
# macOS: --strip-components is not supported
$ tar -xzf pkg.tar.gz --strip-components=1
tar: Option --strip-components is not supported
Traits: most open-source/binary tarballs wrap everything in a top-level directory (pkg/); extracting directly leaves an extra layer or scatters files into the wrong location. GNU tar (Linux/WSL) supports --strip-components; macOS ships BSD tar, which does not — it errors with Option --strip-components is not supported.
Cause
Members of a tarball carry the top-level prefix from when the archive was created; tar -xzf restores paths verbatim. --strip-components=N removes the first N path components on extraction. Two common confusions:
- GNU tar supports
--strip-components; BSD tar (macOS default) does not (only-ssubstitution or nothing); - wrong N: if N exceeds the actual path depth, members are skipped SILENTLY (no error, no files) — harder to notice than an extra layer.
Solution
- Inspect the archive first:
tar -tzf pkg.tar.gz(or| head) — count the actual top-level path depth. - Strip one top-level layer:
tar -xzf pkg.tar.gz --strip-components=1(GNU tar / Linux / WSL);
always mkdir -p out and use -C out so files land in a known directory.
- macOS (BSD tar) alternatives:
- install GNU tar:
brew install gnu-tar, thengtar -xzf pkg.tar.gz --strip-components=1; - or extract to a temp dir and
mv pkg/* .(fine for simple cases).
- If unsure about N:
tar -tzffirst, then verify withfind/lsafter extraction —
over-stripping exits 0 with no files, so check results, not just exit codes.
- In scripts: extract with
tar -xzf <pkg> -C <dir> --strip-components=1and assert a key file exists afterwards.
Verification Evidence
- Local repro (2026-08-29, WSL Ubuntu, GNU tar 1.35, fully local):
- Built
pkg/{a.txt,b.txt}intopkg.tar.gz(with the pkg/ top-level layer); - Plain extract →
out1/pkg/a.txt,out1/pkg/b.txt(extra layer, matches the symptom); --strip-components=1→out2/a.txt,out2/b.txt(prefix stripped);- Negative case:
--strip-components=2(deeper than the path) → exit 0 but NOTHING extracted (silent skip, measured); - Tool version:
tar (GNU tar) 1.35. - The macOS BSD tar
Option --strip-components is not supportedmessage is documented from the source (SO #60486284);
BSD tar itself could not be tested in this Linux environment — alternatives recorded only. Evidence details kept locally (2026-08-29)
Applicable tools (1)
This problem is linked from the tool pages below — reachable from either side.
tarSource & evidence
Source: https://stackoverflow.com/questions/60486284/option-not-supported-in-mac-terminal
← Coding Agents & Terminal domain | Problem Catalog Experience | Facing another issue? Go to the Helpdesk