# tarx — tar without the flag archaeology One grammar for the five things tar is actually used for: pack, unpack, list, ship over ssh, clone a tree. Compression, gpg and a live progress bar come free. Quick card: **`tarx-cheat`**. Raw pipeline: **`tarx -n …`**. ## Pack - **`tarx -a -xz9e proj/`** — `proj.tar.xz`, maximum xz, every core. Slowest, smallest. - **`tarx -a -zst19 proj/`** — `proj.tar.zst`. The sane modern default: near-xz ratios, far faster. - **`-gz9`** · **`-bz2`** · **`-tar`** — gzip (pigz if installed), bzip2, no compression. - One token carries **format + level + extreme**: `-xz9e` = `xz -9e`. `-zst19`, `-gz6`, `-bzip29` all parse. - **`-9e`** on its own sets the level when the format is already chosen. - **`-T 4`** — compressor threads. Default `0` = all cores. - **`-o out.tar.xz`** names it; **`-f`** overwrites. Without `-o` the name comes from the source. - **`tarx -a a/ b/ c/ -o all.tar.xz`** — several sources, one archive, each stored under its own basename. ## Which format for which data The one decision that actually changes the outcome. Everything below is about **what the bytes already are**, not how big they are. - **Text-shaped — source, config, logs, JSON, CSV, XML, SQL dumps** — the biggest wins in computing. **`-xz9e`** to put it on a shelf, **`-zst19`** if you will open it again this month. - **Binaries — executables, `.so`, `.dylib`, `.app` bundles** — compress well. **`-xz9e`**. - **Disk and VM images — `.img`, `.qcow2`, `.vmdk`, sparse files** — mostly zeroes, so huge wins. **`-zst19`**, and tarx keeps holes as holes (`--sparse` on GNU tar). - **Git repos, maildirs, wikis** — the loose objects are already zlib, so expect modest gains. **`-zst19`**. - **Thousands of tiny files** — the win is the tar container itself (one stream instead of N files, no per-file slack). Any codec. ## Already compressed — use `-tar` and skip the CPU entirely Recompressing compressed bytes typically buys **1% or less**, and often makes the file **slightly larger** (compressed data looks random, and every codec adds framing). - **Images** — `jpg` `png` `gif` `heic` `webp` - **Video and audio** — `mp4` `mkv` `mov` `mp3` `flac` `aac` `opus` - **Archives** — `zip` `7z` `rar` `gz` `xz` `zst` `br` - **Zip containers in disguise** — `docx` `xlsx` `pptx` `epub` `jar` `apk` `whl` - **PDF** — its internal streams are deflate already - **Anything encrypted** — `.gpg`, ciphertext, `/dev/urandom`. Incompressible by definition; if it compressed, the encryption would be broken. ## Archive types — what it writes, what it recognises The **flag decides the format**; `-o` only decides the name. Name one thing and compress another and tarx warns you, because a `.tar.xz` full of zstd is a file whose name lies. | Flag | Writes | Tool used | |---|---|---| | `-xz` | `name.tar.xz` | `xz` | | `-gz` | `name.tar.gz` | `pigz`, or `gzip` if pigz is absent | | `-zst` | `name.tar.zst` | `zstd` | | `-bz2` | `name.tar.bz2` | `bzip2` | | `-tar` | `name.tar` | nothing — no compressor in the pipe | | `--encrypt` / `--symmetric` | appends `.gpg` | `gpg` | | `--armor` | appends `.asc` instead | `gpg` | Recognised automatically when extracting or listing — **no flag needed**: | Format | Suffixes understood | |---|---| | xz | `.tar.xz` `.txz` `.tar.lzma` | | gzip | `.tar.gz` `.tgz` | | zstd | `.tar.zst` `.tzst` | | bzip2 | `.tar.bz2` `.tbz2` `.tbz` | | none | `.tar` | | encrypted | `.gpg` `.pgp` `.asc` on top of any of the above | Odd or missing suffix? Force it with **`--format xz`** — the aliases `gzip`, `zstd`, `bzip2`, `lzma`, `tar`, `none`, `raw` all resolve. ## What survives inside the archive - **Regular files, directories, symlinks** — symlinks are stored as links, never followed. - **Hardlinks** — stored once and relinked on extract, which is what `cp -r` loses. - **Sparse files** — holes stay holes. Verified here: a 100 MB sparse file archives to **20 KB** on APFS. bsdtar detects holes natively; on GNU tar, tarx adds `--sparse` for you. - **Permissions and mtime** — restored (`-xpf` on extract). - **macOS extended attributes / AppleDouble `._` files** — **dropped by default**, because they are litter on any non-mac box. **`--mac-metadata`** keeps them. ## Levels Every codec's full range, with peak memory measured on this machine (300 MB input, one thread) — the number that decides whether `-9e -T0` is clever or a swap storm. | Level | Dictionary / block | Peak RAM | Note | |---|---|---|---| | `-xz0` | 256 KB | 4 MB | fastest xz | | `-xz3` | 4 MB | 24 MB | | | `-xz6` | 8 MB | 78 MB | xz's default | | `-xz9` | 64 MB | 611 MB | | | `-xz9e` | 64 MB | 611 MB | same dictionary, more CPU | | `-zst3` | — | 36 MB | zstd's default | | `-zst19` | — | 212 MB | the sweet spot | | `-zst22` | — | **1,008 MB** | `--ultra` added for you, for ~0.1% | | `-gz9` | 32 KB | 2 MB | gzip is always cheap | | `-bz29` | 900 KB | 9 MB | 9 is bzip2's default | - **xz takes `0`–`9`, plus `e`.** `e` (extreme) is xz-only: same dictionary, noticeably more CPU, a fraction of a percent smaller. - **zstd takes `1`–`22`.** Past 19 it needs `--ultra`, which tarx adds automatically. - **gzip and bzip2 take `1`–`9`.** For bzip2 the level **is** the block size (100 KB × level). - **Over the maximum is clamped, with a warning** — `-xz15` becomes `-xz9` and says so. - **Small inputs are far cheaper than the table suggests**: xz shrinks its dictionary to fit, so `-9` on a 3 MB tree peaked at 90 MB, not 611 MB. - **`-T0` multiplies xz's memory by the thread count** — measured 1,519 MB for `-xz9e -T0` on 300 MB. xz uses one thread per block, so it is wide files that cost, not many small ones. - **Decompression is cheap at every level** — `xz -dc` peaked at 4 MB. ## Choosing between them - **`-zst19` is the right default for most work** — close to xz on size, a fraction of the time. - **`-xz9e` is for archival** — the extra percentage point costs the slowest compress and 4× the decompress. - **`-gz9`** — compatibility only. Lands between `-zst3` and `-zst19` on size while being far slower than `-zst3`. Use `pigz` (tarx picks it automatically) or it is slower still. - **`-bz2`** — legacy. Measured below it is **bigger than gzip** on text and its decompression is dramatically the slowest of the lot. Keep it for reading old archives, not writing new ones. - **Decompression is the asymmetry people forget**: zstd and gzip unpack in a fraction of xz's time, and bzip2 is an order of magnitude worse than any of them. If a thing is written once and read often, that matters more than the last 1% of size. - Rule of thumb: **`-zst19` unless it is going on a shelf, then `-xz9e`**. When unsure, `tarx -a -zst19` and move on. ## Measured — Apple M1 Max, 10 cores, macOS 26.5 Not folklore; run on this machine. `of orig` is the compressed size as a percentage of the input. **Text — 2.7 MB of dictionary words + shell config (natural prose and code)** | codec | of orig | compress | decompress | |---|---|---|---| | `-tar` | 100.0% | 0.01s | 0.01s | | `-gz9` | 29.8% | 0.30s (pigz 0.07s) | 0.01s | | `-zst3` | 33.5% | 0.03s | 0.01s | | `-zst19` | 26.2% | 0.64s | 0.01s | | `-xz6` | 25.3% | 0.63s | 0.04s | | `-xz9e` | **25.2%** | 0.85s | 0.04s | | `-bz2` | 33.6% | 0.15s | 0.06s | xz wins by **1 percentage point** over `-zst19`. bzip2 loses to gzip outright. **Already compressed — 284 MB tar of 400 real png/jpg files** | codec | of orig | compress | decompress | |---|---|---|---| | `-tar` | 100.0% | 0.21s | 0.30s | | `-zst3` | 99.2% | 0.12s | 0.11s | | `-zst19` | 99.1% | 11.9s | 0.09s | | `-zst22` | 99.1% | 65.3s | 0.40s | | `-xz9e` | 99.1% | **94.4s** | 0.54s | | `-bz2` | 99.6% | 23.0s | 11.4s | **94 seconds of ten cores to save 0.9%.** This is the whole argument for `-tar` on media. **Random — 20 MB from /dev/urandom (stands in for encrypted data)** | codec | of orig | |---|---| | `-tar` | 100.0% | | `-gz9` | 100.03% — **larger than the input** | | `-zst19` | 100.00% | | `-xz9e` | 100.01% | | `-bz2` | 100.4% — **larger than the input** | Every codec adds framing it cannot earn back. Compressing ciphertext is strictly a loss. ## Unpack & inspect - **`tarx -e proj.tar.xz.gpg -C out`** — format **and** encryption read off the filename. `out/` is created if missing. - **`tarx proj.tar.xz`** — a bare archive name means extract. **`tarx proj/`** — a bare directory means pack. - **`--strip 1`** — drop the leading path component (the `tar --strip-components` you can never remember). - **`tarx -xzls proj.tar.xz`** / **`tarx -l any.tar.zst`** — list. Encrypted archives ask for the passphrase first. - Listing goes to **stdout unstyled**, so `tarx -l a.tar.xz | wc -l` still means something. ## Encrypt - **`--encrypt -r KEY`** — public-key. Repeat `-r` for several recipients. - **`--encrypt`** with no `-r` — numbered picker over your public keys. - **`TARX_RECIPIENT=key`** — env default, skips the picker entirely. - **`--symmetric`** — passphrase only, no key. Asked twice. - **`--armor`** — ascii-armoured `.asc` instead of binary `.gpg`. - **`--keys`** — list your secret keys and exit. - **`-s` / `--sign`** — sign as well as encrypt. **This is the flag that asks for your passphrase on the way in**, because signing unlocks your key while encrypting does not. It also changes what the archive claims: not merely "only they can read it" but "and it provably came from me, unmodified". - **`-u KEY`** — sign with a specific key rather than your gpg default. - On extraction the signature is verified and reported: **`✔ Good signature from "..."`**. A **bad** signature is fatal, never a warning you could scroll past. - Nothing unencrypted is ever written: tar → compressor → gpg is one pipe. ## Passphrases — typed in the terminal, masked - The prompt is drawn here, in the terminal: **` passphrase: •••••••`**, one dot per keystroke, `ECHO` off so the real characters never reach the screen or the scrollback. - **`--show-passphrase`** — echo the literal characters instead of dots, for when you want to see what you typed. - **Backspace** fixes a typo, **Ctrl-U** clears the line, **Ctrl-C** aborts. - Read from `/dev/tty` (stdin is busy carrying archive bytes) and handed to gpg on a **private `--passphrase-fd` pipe**. - **Never argv** (so never visible in `ps`), **never the environment**, **never a pinentry-mac popup**. - This is why it works identically on the Ubuntu VM, where pinentry-mac does not exist. - **`--use-agent`** — opt out and let `gpg-agent` + your configured pinentry ask instead. - Your `gpg-agent.conf` has `default-cache-ttl 0`, so the agent path prompts every single time. That is the reason this exists. ## When it asks, and when it cannot - **`--encrypt -r KEY` never asks, by design.** Public-key encryption uses the recipient's **public** key — no secret is unlocked, so there is nothing to prompt for. Every tool behaves this way; it is not tarx being clever. - **`--encrypt -r KEY --sign` does ask.** If you are used to `gpg -se -r` prompting, signing is the reason. Add `-s` and you get the prompt, plus proof of origin. - **`--symmetric` asks twice** — you are choosing a new passphrase, and that passphrase *is* the only key. - **`-e` on a `.gpg` asks once** — that unlocks your secret key. - If decryption does **not** ask, that secret key has no passphrase on it. Check which of yours are unprotected: `for f in ~/.gnupg/private-keys-v1.d/*.key; do strings "$f" | grep -q protected-private-key || echo "UNPROTECTED $f"; done` - Add one with **`gpg --edit-key KEYID`** → **`passwd`** → `save`. - Want a password on the archive rather than on your key? That is **`--symmetric`**. ## Over ssh — nothing lands on disk in between - **`tarx -a proj/ --push user@host:/opt`** — pack here, unpack there, in one stream. - **`tarx -a proj/ --to user@host:/b/x.tar.xz`** — write the finished archive as a remote file. Encryptable. - **`tarx -e --from user@host:/b/x.tar.xz`** — fetch a remote archive and unpack locally. - **`tarx --pull user@host:/var/log -C ./logs`** — stream a remote tree down. The far end compresses, so it is the wire you save. - **`tarx --clone /src /dst`** — local tree copy that keeps **hardlinks and sparse files** (what `cp -r` loses). - `--push` unpacks remotely, so it refuses `--encrypt` — the far end could not read it. Use `--to`. ## Housekeeping - **`--exclude '*.log'`** — repeatable pattern. **`--clean`** — drop `.DS_Store`, `.git`, `__pycache__`, `node_modules`, `.venv`. - **`-n`** / **`--dry-run`** — print the exact shell pipeline and run nothing. - **`-v`** — list every file (turns the animation off). **`--raw`** — no banner, no bar. - **Ctrl-C** deletes the half-written archive and reaps the pipeline. An interrupted archive is a trap, not a file. ## Why it does not just call `tar -cJf` - **`XZ_OPT`** is honoured by GNU tar, not reliably by bsdtar. **`--options xz:compression-level=9`** is bsdtar-only. - **`du -sb`** does not exist on macOS, so the usual `pv -s $(du -sb …)` recipe is Linux-only. - tarx runs the **universal pipe** (`tar -cf - … | xz …`) and sizes the tree with its own walk, so macOS and Linux take one code path. - **`--sparse`** and **`--no-mac-metadata`** are *probed by running tar*, not by scraping `--help` — bsdtar's help lists neither. - The progress bar is an internal pump thread, not `pv`, which a stock Ubuntu box does not have. > Stdlib Python only — `scp ~/tarx vm:~/.local/bin/` and it works. Sections: `tarx-cheat pack|unpack|crypt|ssh|raw`. Full flags: `tarx -h`.