GNU tar
$ tar Foundation Med Risktar is installed across virtually every Linux, macOS, and container image. Agents can inspect archive entries read-only with tar -tf before extracting into an isolated -C directory, while avoiding untrusted archive path-traversal or accidental file overwrites.
brew install gnu-tar Archive creation and extraction run natively on local disk/streams with zero reason to wrap in MCP.
Agent-Readiness Checklist
Local Probe EvidenceCaptured --help excerpt
tar(bsdtar): manipulate archive files
First option must be a mode specifier:
-c Create -r Add/Replace -t List -u Update -x Extract
Common Options:
-b # Use # 512-byte records per I/O block
-f <filename> Location of archive
-v Verbose
-w Interactive
Create: tar -c [options] [<file> | <dir> | @<archive> | -C <dir> ]
<file>, <dir> add these items to archive
-z, -j, -J, --lzma Compress archive with gzip/bzip2/xz/lzma
--format {ustar|pax|cpio|shar} Select archive format
--exclude <pattern> Skip files that match pattern
-C <dir> Change to <dir> before processing remaining files
@<archive> Add entries from <archive> to output
List: tar -t [options] [<patterns>]
<patterns> If specified, list only entries that match
Extract: tar -x [options] [<patterns>]
<patterns> If specified, extract only entries that match
-k Keep (don't overwrite) existing files
-m Don't restore modification times
-O Write entries to stdout, don't restore to disk
-p Restore permissions (including ACLs, owner, file flags)
bsdtar 3.5.3 - libarchive 3.7.4 zlib/1.2.12 liblzma/5.4.3 bz2lib/1.0.8 FCRS-1.0 6-Dimension Breakdown
Non-interactive and ubiquitous, but lacks --json output and suffers minor BSD vs GNU flag divergence on macOS.
- POSIX flags work headlessly; GNU vs BSD long-flag differences exist
Extracting archives can overwrite existing files silently unless -k and -C are used.
- Overwrites files on extract by default without
-k(--keep-old-files)
Available everywhere (tar preinstalled on Linux/macOS; brew install gnu-tar gives gtar on macOS).
- Standard system tool across Unix platforms
Indispensable for reading, verifying, and packaging release tarballs in CI and workspaces.
- Universal archive format supported across toolchains
Foundational GNU Project utility maintained continuously for decades.
- GNU foundation stewardship under GPL-3.0
Comprehensive GNU manual and man pages.
- Official GNU tar manual at gnu.org
Security, Auth & Guardrails
None required; operates on local files and stdio.
100% free, offline, and open-source (GPL-3.0).
# tar Agent Rules - ALWAYS inspect untrusted tarballs with `tar -tf` first (check for `..` or absolute paths) and extract into a fresh `-C <dir>`. - Note GNU `tar` (`gtar` on macOS) vs BSD `tar` flag differences—stick to portable POSIX flags (`-c`, `-x`, `-t`, `-v`, `-f`, `-z`, `-C`).
Agent-Ready Command Recipes
Safe Read-Only Queries
tar -tvf release.tar.gz
Prints file paths, permissions, and sizes inside the archive without writing to disk.
Controlled Writes & Previews
tar -xvkf release.tar.gz -C ./staging
Uses -k (--keep-old-files) and -C to prevent overwriting existing files or polluting cwd.
Strengths for Agents
- + Preinstalled across virtually all Linux containers, CI runners, and macOS hosts.
- + Supports read-only listing (
-tf/-tvf) and directory scoping (-C).
Caveats & Pitfalls
- ! Default extraction overwrites existing files unless
-k(--keep-old-files) is specified. - ! GNU-only long flags (like
--zstdor--transform) may fail on macOS stock BSDtar.