Tar Command Builder
Pick the task and get the exact tar command — quoted for POSIX shells, with bsdtar and GNU tar shown separately where they differ.
tar -czvf archive.tar.gz src
Verified by execution on bsdtar 3.5.3 - libarchive 3.7.4 zlib/1.2.12 liblzma/5.4.3 bz2lib/1.0.8.
What each part does, in the order tar reads it.
- The archiver itself; everything after it is read left to right.
- c — create a new archive from the listed paths.
- z — filter the archive through gzip.
- v — print each member name as it is processed.
- f — the very next word is the archive file. Keep f last in the bundle.
- A path or member pattern, quoted whenever the shell would reinterpret it.
Identical here — bsdtar and GNU tar accept this exact command.
Written from the GNU tar manual — not executed on the machine that verified this page.
What each part does, in the order tar reads it.
- The archiver itself; everything after it is read left to right.
- c — create a new archive from the listed paths.
- z — filter the archive through gzip.
- v — print each member name as it is processed.
- f — the very next word is the archive file. Keep f last in the bundle.
- A path or member pattern, quoted whenever the shell would reinterpret it.
The engine reported nothing about this command.
-cfzv writes your archive to a file named zv
In a bundled group, f takes the REST of the cluster as the file name: the verified run exited 0 and left the archive in a file called zv. Keep f last — -czvf — so the name after the bundle is the one used.
tar -cfzv srcLeading slashes are stripped from stored names
Archiving an absolute path stores the member without its leading slash — the verified run printed tar's own notice. Extraction therefore lands relative to where you run it, which is safer than writing into / but surprises people restoring backups.
tar -czf abs.tar.gz "$PWD/src/a.txt"--strip-components counts directories, not characters
With members like src/a.txt, one stripped component turns them into a.txt — the verified run left a.txt and sub in the target folder. Count the leading directories in the listing before you pick the number.
tar -xzf archive.tar.gz -C out --strip-components=1A plain extract replaces edited files without a word
The verified run edited an extracted file, re-extracted, and the edit was gone — exit code 0, no prompt. List first, or extract with -k so existing files win.
tar -xzf archive.tar.gz -C ovr
Keyboard: / focuses the archive field · Ctrl ↵ copies the active card · Ctrl C copies the bsdtar command when nothing is selected · Ctrl ⇧ C always copies it.
Do it offline:$ tar -czvf archive.tar.gz src
How to use it
- Choose what tar should do with the archive: pack paths into one, unpack one, print its members, or add files to an uncompressed one.
- Name the archive file and list the paths — directories to pack, or member patterns to pull out. Empty rows are simply skipped.
- Set compression and the option band: excludes, a -C directory, strip-components, verbosity, symlink and overwrite behaviour.
- Copy from the card matching the tar you are holding — bsdtar ships with macOS, GNU tar with most Linux distributions.
Pick the task — create, extract, list or append — and read off the matching tar invocation, assembled in the order tar parses it and quoted wherever a shell would misread a name. Two cards keep the dialects honest: bsdtar flags are verified by execution — all but --zstd, which the card marks as cited — the GNU card cites its manual, and the two only split where they truly differ. Flags you cannot combine are named instead of emitted.
Examples
Create archive.tar.gz from src, verbosetar -czvf archive.tar.gz srcThe bundle reads c-z-v-f: task first, f last, because f claims the next word as the archive name. This exact line is the golden pack's first executed case.
List members without touching disktar -tzf archive.tar.gzt prints member names and writes nothing, which makes it the rehearsal for any extract you are unsure about.
Extract into out/, dropping the top foldertar -xzf archive.tar.gz -C out --strip-components=1One stripped component turned src/a.txt into a.txt in the verified run — the archive's own top directory disappears and everything lands directly in out.
Create, skipping every *.txt filetar -czf archive.tar.gz --exclude '*.txt' srcThe quotes around the pattern are load-bearing: unquoted, the shell expands *.txt against your current directory before tar sees it. The verified archive kept only src/ and src/sub/.
Create a .tar.xz for a better ratiotar -cJvf archive.tar.xz srcCapital J selects xz, lowercase j selects bzip2 — one shifted key apart, and the archive still opens either way only if the flag and the recipient's tar agree.
Re-extract without clobbering local editstar -xzkf archive.tar.gz -C outk means files already on disk win. In the verified pair of runs, an edited file survived the -k pass and was silently reverted by the plain one.
Every example on this page is executed against the same engine that powers the tool, on every build.
Gotchas worth knowing
Bundle order is load-bearing, and f must sit last
tar reads the bundled letters left to right and f takes an argument, so everything after f in the same cluster becomes the file name. The golden run of tar -cfzv src exited 0 and quietly wrote the archive to a file called zv — no error, just a wrong name. The builder therefore always closes the bundle with f.
Leading slashes never survive into an archive
Archive an absolute path and bsdtar answers with its notice — tar: Removing leading '/' from member names — while GNU tar does the same unless -P is set. Members are stored relative, so a later extract lands under the current directory rather than over the live filesystem. The tool warns per absolute path row.
strip-components counts directories, extraction overwrites
The two extract surprises travel together: --strip-components=1 removes exactly one leading folder from every member name, and a plain extract replaces existing files with exit code 0 and no prompt. The tool marks such commands, puts the matching list line in the warning card, and offers -k as the safe default.
What this page deliberately does not do
No archive bytes are read, written, packed or unpacked here — the output is one line of text, and the gzip decompressor is the sibling tool for transforming data in the browser. Also out of scope rather than half-supported: appending to a compressed archive, cpio/pax/shar output, remote tape targets, --format selection, incremental -g archives, ACLs, extended attributes and sparse files. On format: bsdtar writes its pax default, which lifts the ustar format's 100-character member-name limit, so --format is named here, never emitted. A trailing slash on a path row is inert for tar — it changes behaviour in rsync, not here.
Common errors
No files or directories are listed to archive — this mode needs at least one path. Add a path row, for example src.- Create and append refuse to emit a command with nothing to pack; list and extract run happily without member rows.
--strip-components is 0 — this builder accepts 1 to 99. Leave the field empty to keep every leading directory.- Zero strips nothing, so typing it usually means the field should be empty — the refusal says so instead of emitting a no-op.
Path 1 ("/var/log") is absolute — on create, bsdtar strips it ("tar: Removing leading '/' from member names") and GNU tar does the same unless -P is set, so members are stored without the leading /. Use a relative path with -C if you want control over the stored names.- A warning, not a refusal: the command still emits, with tar's own stripping notice quoted so the stored names are no surprise.
A member pattern holds a wildcard — bsdtar matches it natively, but GNU tar takes member names literally unless --wildcards is set, so the GNU card adds it. bsdtar refuses that option outright ("tar: Option --wildcards is not supported").- The one place the two dialect cards split in this builder — each card shows only what its tar accepts.
The archive name is 4097 characters — this builder accepts up to 4096 characters per field. Shorten it; nothing is truncated for you.- Caps are typed refusals: over the limit nothing is emitted, because a silently shortened value would be a different command.
FAQ
Which tar is this page building for?
Both of the ones you are likely to have. macOS ships bsdtar from libarchive; most Linux distributions ship GNU tar. Every tar line printed on this page was executed on the recorded host and the GNU card is cited to the GNU manual, so when the cards agree the line is genuinely portable, and when they split you can see exactly why.
Can it open or compress an archive for me?
No — its whole product is the command line, and that is a feature: you can prepare an invocation for a server you have not reached yet, with nothing uploaded anywhere. When the goal is to inflate gzip data right now, the in-browser gzip decompressor is the right sibling tool for that job.
Why does append refuse my .tar.gz?
Because tar itself does. Compressed archives are one continuous stream, so r mode cannot splice members onto the end — the verified host answers with tar: Cannot append to compressed archive. Append to a plain .tar, or re-create the archive with the extra paths included.
Keyboard shortcuts
- /
- Focus the archive field.
- ⌘/Ctrl + Enter
- Copy the active card's command.