How to Create and Extract .tar.gz Archives in Linux (tar)

tar bundles multiple files and directories into a single archive file, optionally compressed with gzip.

Published September 30, 2026

tar bundles files into one archive and can compress it with gzip. Create with tar -czf, extract with tar -xzf.

How it works

The flags: c create, x extract, z gzip, f file name, v verbose, t list contents.

Without -z, tar only bundles; the .tar.gz is tar plus gzip.

Try it

tar -czf backup.tar.gz project/
tar -tzf backup.tar.gz | head
project/app.js

Practical examples

Create

tar -czf site.tar.gz /var/www/site

Extract here

tar -xzf site.tar.gz

Extract to a folder

tar -xzf site.tar.gz -C /opt/

List without extracting

tar -tzf site.tar.gz

Common mistakes

  • Mixing argument order (put f last before the filename).
  • Extracting into the wrong directory.
  • Archives with absolute paths overwriting system files.

Key takeaways

  • c/x, z, f are the essentials.
  • -C chooses the destination.
  • List with -t before extracting.

FAQ

tar.gz vs zip?

tar.gz preserves Unix permissions; zip is more universal.

How do I use xz or zstd?

Use -J for xz or --zstd.

More Linux articles