How To Extract .tar.gz and .zip Files using Linux Command Line

How To Extract .tar.gz and .zip Files using Linux Command Line

GNU `tar’ saves many files together into a single tape or disk archive, and can restore individual files from the archive. Tar was created by with a mind to compress the entire files, folder and sub-folder etc. Initially, tar archives were used to store files conveniently on magnetic tape. The name “tar” was coined from the word “tape archiver”. The benefits of tar is that the entire files is compresses in a folder .tar.gz extension which reduces the files sizes and also it is very useful while transferring the folder/subfolder or a project without loosing any data. Using this command we can also decompress the files, folder, sub-folder that we have gzip using tar command. Enough of theory part now open the command-line terminal and type the following commands as follows:-

Extracting .tar.gz files

If you compressed the file in gzip format, using this command decompress the files/folder:

$ tar xvzf file.tar.gz

Where,
x = extract files from an archive
v = verbosely list files processed
z = gzipped files eg. for tar.gz
f = use archive file or device ARCHIVE

To decompress the tar.gz file into directory use the command below:

$ tar xvzf file.tar.gz -C /path/to/somedirectory

Where -C is an argument which is used defined the path.

To decompress tar.gz folder compress with tar.gz use the following command:

$tar -xvzf test.tar.gz

Extracting .tar.bz2 files

This is same as the gzip decompression. The only difference is that the z option has been replaced by the j option. In-order to decompress .tar.bz2 use the following command:

$ tar xvjf file.tar.bz2

Where j tells tar to read or write archives using the bzip2 compressor.

This Section is for .zip decompression.

Since there are many compression available in the Unix world but personally we would like to just you to use the .zip because it is easy to use and potable in every environment.

Inorder to Compess a directory using .zip use the following command as follows:-

$ zip -r myfiles.zip mydir

Where -r stands for recursive and read the entire directory tree at once

Inorder to decompress the myfiles.zip use the following command as follows:-

$ unzip myfiles.zip

If you have any query drop a question in the comment section.

extract tar to specific directorylinux trickstar command examplestar extract to new directory
Comments (0)
Add Comment