zip

Archive and package files to a gzip or pkzip format

Syntax:

zip [-options] [-b path] [-t mmddyyyy] [-n suffixes]
    [zipfile list] [-xi list]

Runs on:

QNX Neutrino, Microsoft Windows

Targets:

x86 only

Options:

-0 to -9
Regulate the speed of compression, where -0 indicates no compression, -1 (“one”) indicates the fastest compression method (less compression) and -9 indicates the slowest compression method (optimal compression). The default compression level is -6.
-@
Read names from standard input.
-A
Adjust self-extracting exe.
-b path
Use the specified path for the temporary zip archive.
-c
Add one-line comments for each file. File operations (adding, updating) are done first, and then the utility prompts for one-line comments for each file.
-D
Don't create entries in the zip file for directories. Directory entries are created by default to allow their attributes to be saved in the zip archive.
-d
Delete entries from a zip file.
-e
Encrypt the archive.
-F
Fix the zip file. Use this option if some portions of the file are missing.
-FF
Try harder to fix the zip file.
-f
Freshen (replace) only the files that have changed.
-h
Display a help message.
-h2
Show more help.
-i
Include only specified files. For example:
zip -r foo . -i \*.c
This command includes only the files that end in .c in the current directory and its subdirectories.
-J
Strip any prepended data (i.e. a SFX stub) from the file.
-j
Junk the path to the file; store just the name of the saved file.
-L
Display the zip license.
-l
Convert the UNIX end-of-line character LF to the MS-DOS convention, CR LF. Use -ll to convert the CR LF convention back to the end-of-line character, LF.

Note: Don't use these options on binary files.

-m
Move the specified files into the zip file and delete the target directories/files.
-n suffixes
Don't attempt to compress files named with the suffixes indicated. You can use either colons or semicolons to separate the suffixes.
-o
Set the “last modified” time on the zip file to match the “last modified” time on the zip archive entries.
-P password
Use the given password to encrypt the archive entries.

Note: Specifying a plain-text password on the command line or in a script can be a security problem.

-q
Change to quiet mode by eliminating informational messages and command prompts.
-R
Recurse into the directories starting at the current directory.
-r
Recurse into the directories.
-T
Test the integrity of the new zip file.
-t mmddyyyy
Don't operate on files modified prior to the specified date, where mm is the month, dd represents the day of the month, and yyyy is the year.
-tt mmddyyyy
Don't operate on files modified after or at the specified date, where mm is the month, dd represents the day of the month, and yyyy is the year.
-u
Update only changed or new files.
-v
Be verbose, or print version information.
-X
Don't save extra file attributes.
-x files
Explicitly exclude the files specified. For example:

zip -r foo foo -x \*.o
includes the contents of foo in foo.zip, while it excludes all the files that end in .o.
-y
Store symbolic links as links instead of as the referenced files.
-z
Add a comment to the zip file.

Description:

The zip utility is a compression and file-packaging utility. A companion program (unzip), unpacks zip archives. The zip and unzip programs can work with archives produced by PKZIP; PKZIP and PKUNZIP can work with archives produced by the zip utility.

The zip utility is useful for packaging a set of files for distribution, for archiving files, and for saving disk space by temporarily compressing unused files or directories.

This utility puts one or more compressed files into a single zip archive, along with information about the files, such as name, path, date, time of last modification, protection, and check information to verify file integrity.

You can use a single command to pack an entire directory structure into a zip archive. Compression ratios of 2:1 to 3:1 are common for text files. The zip utility has one compression method (deflation) and can also store files without compression; zip automatically chooses the better of the two for each file to be compressed.

When zip is given the name of an existing zip archive, it replaces identically named entries in the archive or adds entries for new names.

For example, if foo.zip exists and contains foo/file1 and foo/file2, and the directory foo contains the files foo/file1 and foo/file3, then:

zip -r foo foo

replaces foo/file1 in foo.zip and adds foo/file3 to foo.zip. Then, foo.zip contains foo/file1, foo/file2, and foo/file3; foo/file2 remains unchanged.

Examples:

Create an archive called stuff.zip, for example, and put all the files in the current directory in it, in compressed form:

zip stuff *

The .zip suffix is added automatically, unless the archive name given contains a dot already; this allows the explicit specification of other suffixes.

Because of filename substitution, files starting with “.” are not included; to include these to the file:

zip stuff .* *


Note: This command doesn't include any subdirectories from the current directory.

Zip up an entire directory:

zip -r foo foo

This command creates the archive foo.zip, containing all the files and directories in the directory foo that are contained within the current directory.

You may want to make a zip archive that contains the files in foo, without recording the directory name foo. Use the -j option to leave off the paths:

zip -j foo foo/*

If you're short on disk space, you might not have enough room to hold both the original directory and the corresponding compressed zip archive. In this case, you can create the archive in steps using the -m option.

For example, if foo contains the subdirectories tom, dick, and harry, you can perform these commands:

zip -rm foo foo/tom
zip -rm foo foo/dick
zip -rm foo foo/harry

to create a directory called foo.zip. The first command creates the foo.zip directory, and the next two commands add to it. As each zip command completes, the last created archive is deleted, making room for the next zip command to function.

Environment variables:

ZIPOPT
A set of default options for zip. For example:

export ZIPOPT="-D"

Exit status:

0
The operation succeeded.
2
An error occurred; the operation failed.
3
A generic error in the zipfile format was detected, but processing may have completed successfully anyway; a warning was generated in the process.
4
zip was unable to allocate memory for one or more buffers during program initialization.
5
A severe error in the zipfile format was detected; processing probably failed immediately.
6
Entry too large to be split with zipsplit.
7
Invalid comment format.
8
zip -T failed or out of memory.
9
The user aborted zip prematurely with Ctrl-C or a similar command.
10
zip encountered an error while using a temporary file.
11
Read or seek error.
12
zip has nothing to do.
13
Missing or empty zip file.
14
Error writing to a file.
15
zip was unable to create a file to write to.
16
Bad command-line parameters.
18
zip could not open a specified file to read.

See also:

freeze, gzip, pax, tar, unzip

Backing Up and Recovering Data in the Neutrino User's Guide