How to archive and extract a .tar.gz file

Shuvo Shams picture Shuvo Shams · Jan 24, 2014 · Viewed 71.6k times · Source

A simple question. On x86 Solaris 10, I tried the following to compress a folder(Data) of files.

tar -cvf /path/to/Data/* | gzip > /path/to/archive/Data.tar.gz

Now, I can list the file names and their sizes using:

gunzip -c Data.tar.gz

However, when I try to uncompress(for validation) Data.tar.gz:

gzip -d Data.tar.gz
tar -xvf Data.tar

I get a "checksum error"

Can someone please suggest the correct way to compress and extract files in Solaris 10. Thanks

Answer

januarvs picture januarvs · Mar 12, 2014

You can do archive in 2 steps:

$ tar cvf archive.tar file* 
$ gzip archive.tar

(It will create archive.tar.gz, while removing archive.tar.)

Extraction also in 2 steps:

$ gunzip archive.tar.gz

(It will create archive.tar and remove archive.tar.gz.)

$ tar xvf archive.tar

To list files inside the .gz file:

gzip -l archive.tar.gz

Alternatively, you can use 7zip which put together all files as well as compress them.

7z a archive.7z Makefile* (to create archive)
7z l archive.7z           (to list files inside the archive)
7z e archive.7z           (to extract)