untar (decompress) a tgz or tbz file in linux

Tags: , ,

We already know how to tar all the files under a directory into a tgz file.  This posts use simple examples to show how to untar a tgz or tar.bz2 file . 

untar a .tar file

x: tells tar to extract the files.

v:  list all of the files one by one in the archive. The “v” stands for “verbose.”

f:  tells tar that a file name is followed.

untar a .tgz or tar.gz file

If the file extension is .tgz or tar.gz, that means the file is compressed using a gZip compressor. we can untar the file using the following command:

The means of the options:

x: tells tar to extract the files.

v:  list all of the files one by one in the archive. The “v” stands for “verbose.”

z: The z option is very important and tells the tar command to uncompress the file (gzip).

f:  tells tar that a file name is followed.

untar a tar.bz2 or .tbz file

We can use the following command to untar a file compressed using a bZip2 compressor. 

The only difference with the gzip decompression is that j option is used here to replace the z option used in the gzip decompression.

z: is the uncompress (specifically gzip) flag

j: denotes we will decompress a bzip2 file.

 

The dtrx (do the right Extraction) tool

You may want to use dtrx tool, as it is easier to use than the tar command which has too many options.

On linux we can install the dtrx tool using the following command:

On mac, we can install the dtrx tool using the following command. 

Then using dtrx (do the right extraction), we can simply decompress both gzip and bzip2 files:

Use drtx to decompress gzip file.