Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

taring and gzipping all at once

Status
Not open for further replies.

jerehart

Programmer
Jun 10, 1999
61
US
I am trying to gzip some files and then pipe it into tar but can't get it right.

I have tried:

gzip -vr * | tar cvf /dev/rmt/0 -
tar cvf /dev/rmt/0 `gzip -vr *`
tar cvf /dev/rmt/0 `ls `gzip -vr *``

any ideas?
Miah
 
Hi jerehart,

Hope this helps. Try:
gzip -vr * ; tar cvf /dev/rmt/0 *


Pete
 
I am not familiar with the flags to use with gzip, but here is how I do it with compress:

tar -cvf - dir | compress -c > filename.tar.Z

uncompress -c file | tar -xvf -
 
JaSun,

I have tried that with gzip, but tar files don't compress as much as raw files. any hoop thanks for the ideas guys!

Miah
 
Try this:

gzip -{whatever flags} {filenames to gzip} && tar -cvf tarfile.tar /dev/rmt0 (or wherever you want tarfile). To verify the tarfile looks like you want do tar -tvf tarfilename.tar

Hope this helps. B-) d3funct
vanya43@yahoo.com
The software required `Windows 95 or better', so I installed Linux.

 
d3funct

I tried the command:

gzip -vr * && tar cvf /dev/rmt/0 .

and I the files got gziped but no tar file was made. Asking around no one knows what && is supposed to do. any hints?


Miah
 
&& basically says "do this and then do that", I just ran it on a Solaris 7 machine, and I know it works on Solaris 8 also. The command should gzip them and when finished gzipping it should then do the tar. d3funct
vanya43@yahoo.com
The software required `Windows 95 or better', so I installed Linux.

 
Here is how it is done:

tar -cvf - dir | gzip -c > filename.tar.gz

gunzip -c file | tar -xvf -

This will tar and compress on the fly instead of tarring, then compressing. Should use much less disk space as it runs.

Jason
 
The && talked about above is essentially a short hand way of doing an if statement e.g. in the line:

command 1 && command 2

command 2 will only be executed if command 1 is successful(zero exit status). You can add to this line thus:

command 1 && command 2 || command 3

In this line command 2 gets executed if command 1 is successful and command 3 gets executed if it is not.

In short && means a logical and, || means a logical or.

Cheers,

Stephen
 
Another solution is to get a copy of GNU tar that has a switch to automatically envoke gzip.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top