Extract a .tar.gz archive with tar

Unpack a gzipped tarball into the current directory while printing each file as it is extracted.

LinuxZip & ArchivesFilesTerminalLow risk
Run tar -xvzf archive.tar.gz to extract the archive into the current directory.

01Command

Command
$ tar -xvzf archive.tar.gz

02What it does

The flags are x (extract), v (verbose), z (gzip decompression), f (file follows). GNU tar detects compression automatically, so tar -xf archive.tar.gz also works, and the same command handles .tar.bz2, .tar.xz, and plain .tar. To extract into a specific directory use -C: tar -xzf archive.tar.gz -C /tmp/dest. List contents first with tar -tzf archive.tar.gz to check whether the archive contains a single top-level folder or will splatter files into the current directory.

03Risk

RiskLow risk
!Warning: Never extract an untrusted archive as root or without listing it first — tarballs can contain absolute paths or ../ traversal entries that write outside the target directory.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • tar(1) — an archiving utility
    man7.org · technical · 2026-09-17
    Evidence: The tar man page documents -x to extract, -z to filter through gzip, -v for verbose listing, and -f to specify the archive file.

Last verified: 2026-09-17 · Category: Files & Folders

06Related solutions