Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Extract .tar.gz Files in Linux

One tar command unpacks a .tar.gz archive. Here are the options you need.

VPS and Cloud Servers2 min read2 screenshots

What a .tar.gz file is

  • .tar means "tape archive". It joins many files and folders into one file.
  • .gz means the file is compressed with gzip.

Together, a .tar.gz (or .tgz) file is a compressed bundle of files. It is the most common archive format on Linux.

A .tar.gz file in the file list

Extract an archive

tar -xvf filename.tar.gz
  • -x extracts the files.
  • -v shows the names of the files while it works (verbose).
  • -f names the archive file. It must be the last option before the file name.
  • -z is optional on modern tar. It tells tar that the archive is gzip compressed: tar -xzvf filename.tar.gz.

Example:

tar -xvf tmux-2.1.tar.gz
Extracting a tar.gz file

Extract into a chosen folder

Use -C and give the folder. The folder must exist:

mkdir -p /opt/myapp
tar -xvf filename.tar.gz -C /opt/myapp

Extract only some files

Name the files or folders you want after the archive name:

tar -xvf data.tar.gz home/

List the content without extracting

tar -tvf archive.tar.gz

Create a .tar.gz file

tar -czvf archive.tar.gz folder_name

Why use .tar.gz

  • Smaller size. Compression saves disk space and speeds up downloads.
  • Order. Many files become a single file.
  • Works everywhere. The tar and gzip tools exist on almost every system.

Quick recap

  • tar -xvf file.tar.gz unpacks it.
  • Use -C folder to pick the target.
  • tar -tvf lists the content first.