Extract and Compress .tar.gz file using Linux Command Line

The tar is most common compression format used in GNU/Linux to extract and create compressed archive files and that can be copied to any external machine in an easy way. A tar.gz file is nothing but a gzipped tar archive and its variants is tar.gz. 
 

In this article we will be going to discuss various tar command examples
including how to create archive files using (tar, tar.gz) compression,
how to extract archive file, view content of file, verify a file etc.

To create tar.gz file you can use the below commands:

Create tar.gz file by Compressing an Entire Directory or a single File
tar -czvf name-of-file.tar.gz /source_directory-or-file
Example
tar -czvf v9.7fp10_linuxx64_server.tar.gz /data/server

Here’s what those options actually mean:

-c: Create an archive.
-z: Compress the archive with gzip.
-v: Display progress in the terminal while creating the archive, also known as “verbose” mode. 
-f: Allows you to specify the filename of the archive.

This will compress the contents of source-folder-name to a tar.gz archive format.

Create .tar file
tar -cvf orahow.tar /home/orahow/
Example:
tar -cvf orahow.tar /home/orahow

To extract a tar.gz file you can use the following command:

To unzip/extract the .tar.gz file:
tar -zxvf tar-archive-name.tar.gz
Example:
tar -xzf v9.7fp10_linuxx64_server.tar.gz
It will create new directory to populate unpacked files and directories.

What is inside the .tar and .tar.gz?

View contents of tar and tar.gz file:
tar -tvf filename.tar
tar -tvf filename.tar.gz

That’s all…!!!! Hope this will help you to compress and extract the files in the form of .tar and .tar.gz