Extract or Unzip Tar Gz (.tar.gz, tgz) File in Linux
A TAR file is an archive file that collects and combines several files into one manageable file. This is usually for the purposes of distributing or archiving, and the name comes from “Tape ARchive”.
In this tutorial, we will learn how to extract tar.gz and tgz archives.
By default, most Linux distributions come with the pre-installed
tar command. To extract a tar.gz file, run the below command:
tar -xf archive.tar.gz
--extract option and
f option to specify the archive file name.
During extracting, if you want to print the names of the files use
tar -xvf archive.tar.gz
Tar extracts the archive contents in the current folder by default. If you want to extract to a specific location, then use the
-C (--directory) to extract archive files in a specific directory.
tar -xf archive.tar.gz -C /home/shouts/files
To extract a specific file/s from the tar file, write a space-separated list of file/folder names. Specific files:
tar -xf archive.tar.gz dir1 dir2
tar -xf archive.tar.gz file1 file2
Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.