How To Uncompress and Untar Tar Gz File In Linux, Unix and BSD – POFTUT

How To Uncompress and Untar Tar Gz File In Linux, Unix and BSD


tar and gz formats very popular in Linux, Unix and BSD world. A lot of files like source code, backup, configuration files etc. are compressed with this two formats. As a Linux system administrator we generally face with tar.gz extension files. In this tutorial we will look how to extract them easily.

Tar

Tar is very old and popular format used to put separate file and directories into single file. This is most used technique before compression. Detailed tutorial about tar command be found in the following link.

http://www.poftut.com/how-to-uncompress-and-untar-tar-gz-file-in-linux-unix-and-bsd/

Gz

Gz is the gzip format which is provided by all of the Linux, Unix and BSD files systems. gz command is used to compress, extract and list files and directories.

List Files and Directories

Before extracting or uncompressing the tar.gz file we generally need to list file and directories in the archive. We will use tar command with -tvf option to list them. In this example we will list contents of rarlinux-x64-5.4.0.tar.gz

$ tar -tvf rarlinux-x64-5.4.0.tar.gz
List Files and Directories
List Files and Directories

Extract Entire Tar.gz Archive

The most used operation is extracting entire archive. This will extract all file into new directory. We will use tar command with -xvf option. In this example we will extract all content of the rarlinux-x64-5.4.0.tar.gz

$ tar -xvf rarlinux-x64-5.4.0.tar.gz
Extract Entire Archive
Extract Entire Archive

Extract Single File

Another useful example is extracting single file from the tar.gz archive. We will specify the file or directory we want to extract after the archive name. In this example we will extract file rar/rar.txt from archive.

$ tar -xvf rarlinux-x64-5.4.0.tar.gz  rar/rar.txt

Extract Multiple Files

We can also extract multiple files without extracting the whole archive we will add all files and directories we want to extract one by by. In this example we want to extract rar/rar.txt and rar/license.txt from the archive.

$ tar -xvf rarlinux-x64-5.4.0.tar.gz  rar/rar.txt rar/license.txt
Extract Multiple Files
Extract Multiple Files

LEARN MORE  What Is GZ File Type or Extension? How To Create, Extract and Open Gz File?

Leave a Comment