Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to gzip more than one files together

 
deo swaroop
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

How do i gzip more than one file in a single zip file?

if i provide : gzip file1 file2, it created twi gzip files .

Please let me know if you ve any soln for this.


Regards,
deo Swaroop
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gzip can't create .zip files, only .gz files (or maybe that was just a typo on your part).

The usual approach is to create a TAR archive of files, and then to GZIP the .tar file. The Apache Commons Compress library has tar stream implementations, and its web site has example code.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a reason that the general practice is to first "tar" all the small files into a "tar" file and then use gzip (or bzip2) to compress the tar file. Both of these programs use the basic technique of looking at the input and finding common strings. With all of the small files bundled into the tar file, there are more chances to identify common strings. With the windows-style 'zip' approach, each file is compressed independently, so common strings between files are not used to improve the compression ratio.
 
Russ Nash
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest way to make an archive of more than one file is as follows:

1) Create a temporary folder
2) Copy the files into that folder
3) Make that folder your current directory (i.e. cd temp)
3) Use the command: tar cvzf archivename.tar.gz ./*

This will create a zipped and tared archive called archivename.tar.gz of every file in the current directory and in subdirectories under it.

The file can be extracted into the current directory with: tar zxvf archivename.tar.gz

Hope this helps.

Russ.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic