Back to tools

tar command builder

Create, extract and list archives. Choose what to do, get the tar command with every letter explained, and try it on a sample directory first.

Read an existing tar command

Paste a tar command seen elsewhere: see what it does and whether it is wrong, then fill the form with it.

What follows f is the archive name: in -cfzv the zv after f is taken as the name, not as options. Put f last: -czvf

Create
Look
Extract
More
Build it

The archive to make, such as backup.tar.gz

Separated by blanks; directories go in with everything inside

Names not to pack, separated by blanks; wildcards work: node_modules *.log

Paths in the archive start inside it; with . you pack only what is in it

The command
tar -czvf backup.tar.gz project

The same with long options (easier to read, good in scripts)

tar --create --gzip --verbose --file=backup.tar.gz project

Each part of the command

  1. tar -czvfShort options can be run together: -czvf
  2. cc: create a new archive
  3. zz: gzip, the most common (.tar.gz, .tgz)
  4. vv: name each file as it goes (verbose)
  5. f backup.tar.gzf backup.tar.gz: the archive’s file name. What follows f is the file name, so f goes last in the letters
  6. projectThe files and directories to pack; directories go in with everything inside
Explain
Preview

Run in the simulator in the sample directory /home/user/work; none of your files are touched.

What the command prints

project/
project/logs/
project/logs/app.log
project/logs/old.log
project/node_modules/
project/node_modules/lib/
project/node_modules/lib/index.js
project/README.md
project/src/
project/src/app.js
project/src/util.js

Exit status 0

11 entries in the archive (tar -tvf)

drwxr-xr-x user/user         0 2026-01-15 09:30 project/
drwxr-xr-x user/user         0 2026-01-15 09:30 project/logs/
-rw-r--r-- user/user         8 2026-01-15 09:30 project/logs/app.log
-rw-r--r-- user/user         4 2026-01-15 09:30 project/logs/old.log
drwxr-xr-x user/user         0 2026-01-15 09:30 project/node_modules/
drwxr-xr-x user/user         0 2026-01-15 09:30 project/node_modules/lib/
-rw-r--r-- user/user        20 2026-01-15 09:30 project/node_modules/lib/index.js
-rw-r--r-- user/user        10 2026-01-15 09:30 project/README.md
drwxr-xr-x user/user         0 2026-01-15 09:30 project/src/
-rw-r--r-- user/user        19 2026-01-15 09:30 project/src/app.js
-rw-r--r-- user/user        21 2026-01-15 09:30 project/src/util.js
The sample directory
/home/user/work/
  notes.txt
  project/README.md
  project/logs/app.log
  project/logs/old.log
  project/node_modules/lib/index.js
  project/src/app.js
  project/src/util.js
Good to know
  • A few letters go a long way: c create, r append, x extract, t list; add z (gzip), v (name the files), f (the archive).
  • What follows f is the archive name, so f goes last: -czvf a.tar.gz is right, -cfzv a.tar.gz makes an archive called zv.
  • When extracting or listing, GNU tar recognises the compression: tar -xf archive is enough.
  • Before extracting, look with tar -tf: what is in it, and will it spill all over the directory? To read one file, tar -xOf archive file.
  • -C dir: when creating, "go there, then pack"; when extracting, "extract there", and the directory must exist.
  • --exclude goes before the files to pack; wildcards when extracting need --wildcards.
  • A lone .gz file (not .tar.gz) is opened with gunzip; a .zip with unzip, not tar.
Command reference: tar