5

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

Shuvo Shams
  • 633
  • 4
  • 10
  • 22

3 Answers3

17

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)
januarvs
  • 398
  • 3
  • 7
3

Since you're piping (as you should), you need to use - to indicate stdin or stdout. E.g.

tar -cvf - data/* | gzip > data.tar.gz
gzip -dc data.tar.gz | tar -xvf -
Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • Still getting the following error when I try to extract it back: "tar: directory checksum error". Please advice, thanks – Shuvo Shams Jan 27 '14 at 15:12
  • The above works for me. Are you doing something with the .tar.gz file in between? Are the commands being run on different machines? – Mark Adler Jan 27 '14 at 16:11
3

You have to direct the output of tar cvf to stdout, to be able to read it with gzip:

tar cvf - <path> | gzip > <file>

In general is also recommended to use relative path names. Using a path starting with / can cause problems if you want to unpack it on another system. gnu tar will transform absolute paths into relative. gnu tar also accepts a compression option, so gzip is no longer necessary:

gnutar cvfz <file> <path>

In addition you could do something like:

tar cvf - <path> | ssh remotehost (cd <another dir>; gzip > <file>)

which will change the directory before zipping.

The manual page of Solaris tar, has more examples. See man tar(8).

paridaen
  • 31
  • 3