These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX01/Dealing With ZIP Files

Classnotes | UNIX01 | RecentChanges | Preferences

Under UNIX ZIP files are not widely used. More often than not, you will only see ZIP files used when:
A: The person supplying the ZIP files is a UNIX newbie or otherwise primarily a Windows user.
B: The person supplying the ZIP files must interoperate with Windows users and is looking for the "path of least resistance".

The ZIP algorithms are largely inferior to the alternatives under Linux. GZip can generally compress a bit better than the standard ZIP, and BZip2 is extraordinarily effective at compressing. However, if you do need to deal with ZIP files under UNIX, there are a number of commands you can use:

zip

The zip command creates new ZIP archives. The command line options are very similar to the PKZIP command line options under DOS or Windows. The general format for zip is as follows
 zip [OPTIONS] [ZIPFILE] [FILE1, FILE2, ...]

For example, if I wanted to add the file "zcalc.c" to the new zip file "zcalc.zip", I would issue

 $ zip zcalc zcalc.c

Note here that the .zip extension is completely optional, as zip knows to add it. The above line is equivalent to this one

 $ zip zcalc.zip zcalc.c

If I wanted to ZIP a directory recursively, I would use the "-r" option. For example, if I wanted to ZIP the directory "archive/" into the ZIP file "backup_files.zip", I could issue

 $ zip -r backup_files archive/

There are many more options to zip. For more information, consult zip's man page.

unzip

unzip extracts the files from a ZIP archive. The basic format for an unzip command is as follows:
 unzip [OPTIONS] [ZIPFILE] [FILE1 FILE2 etc] [-x FILE1 FILE2 etc]

If I wanted to simply unzip the "myfiles.zip" archive, I would issue

 $ unzip myfiles.zip

If, however, I only wanted to get the files "pancake_recipe.txt" and "2002-State-Taxes.txt", then I could issue

 $ unzip myfiles.zip pancake_recipe.txt 2002-State-Taxes.txt

I can also exclude files from extraction using the "-x" option. For example, if I wanted to extract everything from "business_archive.zip" except for "SCO_payments.txt" and "SCO_extortion.doc", I would issue

 $ unzip business_archive.zip -x SCO_payments.txt SCO_extortion.doc

Again, unzip has many more options and features. Consult the unzip man page for more information.

zipcloak

Is a utility for creating and dealing with encrypted ZIP files. If simply called with a ZIP file, the default action is to encrypt all files in that ZIP file with a password given at the command line
 $ zipcloak somefile.zip

(again, the .zip extension is optional). If you want to decrypt something, you use the "-d" option

 sam@rygel:~/incoming/src$ zipcloak -d zcalc.zip 
 Enter password: 


Classnotes | UNIX01 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited July 26, 2003 1:22 am (diff)
Search:
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.