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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gzip.... 1

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi. I am using;

`gzip -c file.html > file.tar.gz`;

at the moment, to create a tar.gz file by a script.

A question I have is, how do I put multiple files in the file.tar.gz?

Any help will be much appreciated :)
Andy
 
To do multiple files, just list all of the files like:
`gzip -c file1.html file2.html file3.html > file.tar.gz`;

or if appropriate you can use wildcards like:

`gzip -c *.html > file.tar.gz`;
 
gzip isn't really intended to create zip-type archives. It's main purpose is just to compress single files. To put multiple files into a gzip'ed archive you should tar them together first. Here's a quote from the gzip man page:

"If you wish to create a single archive file with multiple members so that members can later be extracted independently, use an archiver such as tar or zip. GNU tar supports the -z option to invoke gzip transparently. gzip
is designed as a complement to tar, not as a replacement."
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
How would I do this then? Sorry if I am being stupid, but I am new to gzip, and Perl!

Thanks

Andy
 
The tar command would look something like this:
Code:
tar cf file.tar file1 file2 file3 ...
then the gzip command would be:
Code:
gzip file.tar
The result would be file.tar.gz. You can also put directory names instead of file names on the tar command, and it will include all files in the directory, WITH THE DIRECTORY NAME ATTACHED. To recover the files:
Code:
gunzip file.tar.gz
tar xf file.tar
Make sure you do this in the directory you started from, so the files will go in their proper places.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Hi. I am using;

Code:
`gzip -c file.html > file.tar.gz`;

at the moment, to create a tar.gz file by a script.


That's not a .tar.gz file. That's a .gz file. These can only contain one file.

If you want to make a .tar.gz file, you can create a .tar file, which may containe multiple files, and gzip it.

tar has an option built-in, to immediately compress the generated .tar file. Use the -z command line switch.

Typical command line:

Code:
tar -czf file.tar.gz -C filesdir file1 file2 ...

Use "." for the filelist if you want to compress everything in a directory. "-C filesdir" is optional.
 
Thanks bartl. I've never seen the -z switch before. Quite useful!
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top