Commandtar

Extract a .tar.gz archive

Unpacks a .tar.gz archive into the current directory, decompressing the gzip layer and extracting every file in a single command.

Last updated

Commandtar
tar -xzvf archive.tar.gz

How it works

-x extracts (as opposed to -c, which creates); -z decompresses the gzip layer on the fly so you don't need a separate gunzip step first; -v lists each file as it's extracted, which is genuinely useful for confirming what actually shipped inside the archive, not just watching progress; -f names the archive to read from, and it must come LAST in the combined flag cluster since tar treats the very next command-line argument as that filename.

This is the one command most people actually need to remember for tar — extract, decompress and show progress, all from a single flag cluster with the filename right after it.

Watch out for

  • This extracts into the CURRENT directory by default; add -C /target/dir to extract somewhere else without cd-ing there first — note the target directory must already exist, since tar won't create it for you.
  • -f has to be the last letter in the combined cluster (-xzvf, not -fxzv) because whatever follows -f on the command line is read as the archive path — reordering the flags breaks that parse.
  • Modern GNU and BSD tar both auto-detect gzip/bzip2/xz compression from the archive's contents even without -z, but including it explicitly documents intent clearly and keeps the command working on older tar versions that need the hint.

Related in Commands