Reputation: 653
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
Upvotes: 5
Views: 74975
Reputation: 508
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)
Upvotes: 17
Reputation: 31
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).
Upvotes: 3
Reputation: 112422
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 -
Upvotes: 3