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
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 | sortOutput
project/README.md project/src/a.txt
Extract into another directory
-C DIR changes to DIR before extracting. The directory must already exist.
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/dataOutput
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.
mkdir -p data && echo 'x' > data/file.txt && tar -czf data.tar.gz data
tar -tzf data.tar.gzOutput
data/ data/file.txt
Options
| Option | Meaning |
|---|---|
| -x | Extract files from the archive |
| -z | Filter the archive through gzip |
| -f FILE | Use FILE as the archive |
| -C DIR | Change to DIR before extracting |
| -t | List the archive contents |
| -v | Print each file name as it is processed |
Sources
Related pages
errors · bashbash: command not found (exit status 127)bash prints "command not found" and exits with status 127 when a command is not in PATH, not installed or misspelled. Check with command -v and fix PATH.errors · findfind: paths must precede expressionfind reports paths must precede expression when an unquoted glob such as *.txt is expanded by the shell into several file names. Quote it: find . -name '*.txt'.cheat sheets · awkawk cheat sheet: fields, patterns, sums and printfawk cheat sheet: print fields, change the separator, filter rows by pattern or condition, sum and count columns, use BEGIN and END, printf formats and arrays.