*.tar.gz is a very old and popular compression and file format used to store multiple files and directories in a single compressed file. The tar.gz file consists of two types of files where the first format is the
tar format. The tar format is used to put multiple files and folders into a single file in order to copy, move and manage in an easy and reliable way. The gzip is a compression format, extension, algorithm, and tool used to compress a file in an efficient way. The gzip format is popularly used in Unix and Linux systems.
tar command is used to create, zip, unzip and extract the tar.gz files. The
-x option is used to unzip/extract tar.gz files. Alternatively the long-form of -x which is
--extract can be used. By default the tar command do not print any information to the standard output about the extraction.
$ tar -xf blender-2.80.tar.gz
Print Extracted Files and Folders
By default the tar command do not prints extracted files and folders. But we can print every extracted files and folders by using the
-v option like below. The -v option means print verbose information. Alternatively the long form
--verbose can be also used.
$ tar -xvf blender-2.80.tar.gz
Unzip/Extract tar.gz Into Diffrent Path
By default the tar command extracts and unzip the specified tar.gz file into the current working directory. But we can extract the tar.gz file into the different path by using the
-C option. Also the path we want to unzip is specified after the -C option.
$ tar -xf blender-2.80.tar.gz -C /opt/
List tar.gz File Cotents
The contents of the files and folders can be listed with the
-f options without extracting the contents.
$ tar -tf blender-2.80.tar.gz
Alternatively the long form
--list can be used to list files and folders in a tar.gz file.
$ tar --list -f blender-2.80.tar.gz
Extract Specific File From tar.gz
A tar.gz file generally contains multiple files and folders but we may require to extranc one of them not all of them. We can extract specific file from a tar.gz file. We provide the file name we want to extract after the tar.gz file.
$ tar -xf blender-2.80.tar.gz blender-2.80/COPYING
Extract Multiple Files From tar.gz
Also we can extract multiple files from tar.gz file. We just provide the files we want to extract after the tar.gz file.
$ tar -xf blender-2.80.tar.gz blender-2.80/COPYING blender-2.80/CMakeLists.t
Extract Specific Extension from tar.gz
Another powerful feature of the tar command is it can be used to extract specific file extension from all over the tar.gz file. The
--wildcard option is used to specify the extension. In the following example we extract all files with the
$ tar -xf blender-2.80.tar.gz --wildcards '*.txt'