Extract .tar.gz File in Linux

Last updated on Dec 28, 2019 in Linux

.tar.gz is a compressed tar archive file created with tar using -z parameter (gzip compression). You can easily extract this type of file by using tar command.

$ tar xvzf myfile.tar.gz
  • x tells tar to extract the archive file
  • v is for verbose output
  • z tells tar to use gzip to decompress the file
  • f is for the filename, which is defined as the next argument

This will extract the file in same folder you are at the moment, which is not always the desired outcome. To extract the contents to another folder, use -C argument with the target path:

$ tar xvzf myfile.tar.gz -C /path/to/folder/