File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Linux / UNIX and the fly likes How to gzip more than one files together Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How to gzip more than one files together" Watch "How to gzip more than one files together" New topic

How to gzip more than one files together

deo swaroop
Ranch Hand

Joined: May 21, 2008
Posts: 30
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.

deo Swaroop
Lester Burnham

Joined: Oct 14, 2008
Posts: 1337
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

Joined: Aug 11, 2007
Posts: 4659

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

Joined: Oct 03, 2010
Posts: 2
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.

I agree. Here's the link:
subject: How to gzip more than one files together
It's not a secret anymore!