Skip to content

/commands/tar/extract-tar-gz

tar -xzf: extract a .tar.gz archive

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · tar (GNU tar) 1.35updated 2026-10-20
tool
tar
versions
GNU tar 1.30+, bsdtar 3.x
os
linux, macos, windows

tar -xzf archive.tar.gz extracts a gzip-compressed tar archive into the current directory. -x extracts, -z filters the archive through gzip, and -f names the archive file.

Extract into the current directory

bash
mkdir -p project/src && echo 'hello' > project/src/a.txt && echo 'world' > project/README.md
tar -czf project.tar.gz project
rm -r project
tar -xzf project.tar.gz
find project -type f | sort

Output

project/README.md
project/src/a.txt

Extract into another directory

-C DIR changes to DIR before extracting. The directory must already exist.

bash
mkdir -p data && echo 'x' > data/file.txt && tar -czf data.tar.gz data
mkdir -p out
tar -xzf data.tar.gz -C out
ls out/data

Output

file.txt

List the contents before extracting

-t lists the members without extracting anything. Add -v to either command to see each file as it is processed.

bash
mkdir -p data && echo 'x' > data/file.txt && tar -czf data.tar.gz data
tar -tzf data.tar.gz

Output

data/
data/file.txt

Options

OptionMeaning
-xExtract files from the archive
-zFilter the archive through gzip
-f FILEUse FILE as the archive
-C DIRChange to DIR before extracting
-tList the archive contents
-vPrint each file name as it is processed

Sources