Zipping files greater than 2GB in bash shell

I ve been trying to zip all the files in partcular directory into a single zip file and then transfer it to destination server. command i ve used is like

zip -j $Zipfilename *

the problem is sometimes the total size of all the files is reaching > 2GB so i'm getting below warning

zip warning: name not matched

and files are not getting zipped .Is there is anyother way to do it, without getting the above error? Please help me out!!


Solution 1:

Zip is not known to be able to create ZIPs greater than 2GB in size. For better or worse, Linux has other tools such as tar, gzip, bzip and others that you can use which have a much higher limit on what they can create. However, if you insist on sticking to ZIP, you could try and use the --split-size directive like so:

zip -j --split-size 2g $zipfilename *

In case you're wondering about the alternatives...

Creating with Tar

tar -cf name_of_zip.tar directory/

This will create a simple Tar(ball) file. Good for on-the-fly and when you need to get something out quick.

tar -czf name_of_zip.tar.gz directory/

This creates a Tar-Gzipped file of a directory. tar-gz is a Tar(ball) that has been further compressed by gzip. It's slightly slower than a standard Tar operation, but provides pretty good compression for what you're getting.

tar -cjf name_of_zip.tar.bz directory/

This creates a Tar-BZipped file of a directory. tar-bz is the slowest tar option you can use, but provides the greatest amount of compression on top of the tar.

Untarring is a simple matter of replacing the -c switch with a -x switch. IE:

tar -xzf /tmp/some_file.tar.gz

Which untars the /tmp/some_file.tar.gz tar(ball) into whatever directory I'm currently in.

Creating with gzip

gzip -c file file2 file3 > newfile.gz`

Creates a new gzip file from a file, or a bunch of files.

gzip -cr directory/ > newfile.gz`

Creates a new gzip from a directory.

Unzipping is a matter of simply using gunzip on your gzip file.

Creating with bzip

BZip doesn't do directory traversal, so it's only good for zipping up one-or-many files.

bzip2 -ck file -<number> > compress.bz

where is a number between 1 and 9, 1 being the lowest level of compression and 9 being the highest.

Solution 2:

unzip version 6.0 and zip version 3.0 support greater than 2GB files.

New features in UnZip 6.0, released 20 April 2009:

  • Support PKWARE ZIP64 extensions, allowing Zip archives and Zip archive entries larger than 4 GiBytes and more than 65536 entries within a single Zip archive. This support is currently only available for Unix, OpenVMS and Win32/Win64.
  • Support for bzip2 compression method.

New features in Zip 3.0, released 7 July 2008:

  • large-file support (i.e., > 2GB)
  • support for more than 65536 files per archive
  • multi-part archive support
  • bzip2 compression support