Archive and package files to a pkzip format


zip  [-option ...] [--longoption ...]  [-b path]
     [-n suffixes] [-t date] [-tt date] [zipfile [file ...]]  [-xi list]

Runs on:

QNX Neutrino


-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, one file name per line.
Adjust a self-extracting executable archive. A self-extracting executable archive is created by prepending the SFX stub to an existing archive. The -A option tells zip to adjust the entry offsets stored in the archive to take into account this "preamble" data.
-b path
--temp-path path
Use the specified path for the temporary zip archive.
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. Enter the comment followed by return, or just return for no comment.
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.
Create an archive that contains all new and changed files since the original archive was created. For this to work, the input file list and current directory must be the same as during the original zip operation.

Note that the timezone environment variable TZ should be set according to the local timezone in order for this option to work correctly. A change in timezone since the original archive was created could result in no times matching and all files being included.

A possible approach to backing up a directory might be to create a normal archive of the contents of the directory as a full backup, then use this option to create incremental backups.

Delete entries from a zip file.
Display running byte counts showing the bytes zipped and the bytes to go.
Display a running count of entries zipped and entries to go.
Display dots while each entry is zipped (except on ports that have their own progress indicator). See -ds for setting the dot size. The default is a dot every 10 MB of input file processed. The -v option also displays dots, and this rate is also controlled by -ds.
Display progress dots for the archive instead of for each file. The command:
zip -qdgds 10m

turns off most output except dots every 10 MB.

-ds size
--dot-size size
Set the amount of input file processed for each dot displayed. See -dd to enable the displaying of dots. Setting this option implies -dd. The size is in the format nm, where n is a number and m is a multiplier. Currently m can be k (KB), m (MB), g (GB), or t (TB). The default is 10 MB.

The -v option also displays dots and now defaults to 10 MB also. This rate is also controlled by this option. A size of 0 turns dots off.

This option doesn't control the dots from the "Scanning files" message as zip scans for input files. The dot size for that is fixed at 2 seconds or a fixed number of entries, whichever is longer.

Display the uncompressed size of each entry.
Display the volume (disk) number each entry is being read from, if reading an existing archive, and being written to.
Encrypt the contents of the zip archive using a password that you're prompted to enter (twice) on the terminal.
Fix the zip file. Use this option if some portions of the file are missing.
Try harder to fix the zip file.
Normally zip skips reading any FIFOs (named pipes) encountered, as it can hang if the FIFO isn't being fed. This option tells zip to read the contents of any FIFO it finds.
Synchronize the contents of an archive with the files on the OS.

Normally when an archive is updated, new files are added and changed files are updated but files that no longer exist on the OS are not deleted from the archive. This option enables a mode that checks entries in the archive against the file system.

If the file time and file size of the entry matches that of the OS file, the entry is copied from the old archive instead of being read from the file system and compressed. If the OS file has changed, the entry is read and compressed as usual. If the entry in the archive does not match a file on the OS, the entry is deleted. Enabling this option should create archives that are the same as new archives, but since existing entries are copied instead of compressed, updating an existing archive with -FS can be much faster than creating a new archive. Also consider using -u for updating an archive.

For this option to work, the archive should be updated from the same directory it was created in so the relative paths match. If few files are being copied from the old archive, it may be faster to create a new archive instead.

Note that the timezone environment variable TZ should be set according to the local timezone in order for this option to work correctly. A change in timezone since the original archive was created could result in no times matching and recompression of all files.

This option deletes files from the archive. If you need to preserve the original archive, make a copy of the archive first or use the --out option to output the updated archive to a new file. Even though it may be slower, creating a new archive with a new archive name is safer, avoids mismatches between archive and OS paths, and is preferred.

Freshen (replace) only the files that have changed. Unlike the update option (-u), this doesn't add files that aren't already in the zip archive.
Grow (append to) the specified zip archive, instead of creating a new one. If this operation fails, zip attempts to restore the archive to its original state. If the restoration fails, the archive might become corrupted. This option is ignored when there's no existing archive or when at least one archive member must be updated or deleted.
Display a help message.
Show more help.
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.

Strip any prepended data (i.e., a SFX stub) from the file.
Junk the path to the file; store just the name of the saved file.
Attempt to convert the names and paths to conform to MSDOS, store only the MSDOS attribute (just the user write attribute from Unix), and mark the entry as made under MSDOS (even though it was not); for compatibility with PKUNZIP under MSDOS which cannot handle certain names such as those with two dots.
Display the zip license.
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.
Append to the existing logfile. The default is to overwrite.
-lf logfilepath
--logfile-path logfilepath
Open a logfile at the given path. By default any existing file at that location is overwritten, but if you specify the -la option, an existing file is opened and the new log information appended to any existing information. Only warnings and errors are written to the log unless the -li option is also given, then all information messages are also written to the log.
Include information messages, such as file names being zipped, in the log. The default is to only include the command line, any warnings and errors, and the final status.
Translate the MSDOS end-of-line CR LF into Unix LF. This option should not be used on binary files. This option can be used on MSDOS if the zip file is intended for unzip under Unix. If the file is converted and the file is later determined to be binary a warning is issued and the file is probably corrupted. In this release if -ll detects binary in the first buffer read from a file, zip now issues a warning and skips line end conversion on the file. This check seems to catch all binary files tested, but the original check remains and if a converted file is later determined to be binary that warning is still issued. A new algorithm is now being used for binary detection that should allow line end conversion of text files in UTF-8 and similar encodings.
All input patterns must match at least one file and all input files found must be readable. Normally when an input pattern does not match a file the "name not matched" warning is issued and when an input file has been found but later is missing or not readable a missing or not readable warning is issued. In either case zip continues creating the archive, with missing or unreadable new files being skipped and files already in the archive remaining unchanged. After the archive is created, if any files were not readable zip returns the OPEN error code (18 on most systems) instead of the normal success return (0 on most systems). With -MM set, zip exits as soon as an input pattern is not matched (whenever the "name not matched" warning would be issued) or when an input file is not readable. In either case zip exits with an OPEN error and no archive is created.

This option is useful when a known list of files is to be zipped so any missing or unreadable files will result in an error. It is less useful when used with wildcards, but zip will still exit with an error if any input pattern doesn't match at least one file and if any matched files are unreadable. If you want to create the archive anyway and only need to know if files were skipped, don't use -MM and just check the return code. Also -lf could be useful.

Move the specified files into the zip file and delete the target directories/files. If a directory becomes empty after removal of the files, the directory is also removed. No deletions are done until zip has created the archive without error. This is useful for conserving disk space, but is potentially dangerous, so we recommend you use it in combination with -T to test the archive before removing all input files.
-n suffixes
--suffixes suffixes
Don't attempt to compress files named with the suffixes indicated. You can use either colons or semicolons to separate the suffixes.
Do not perform internal wildcard processing (shell processing of wildcards is still done by the shell unless the arguments are escaped). Useful if a list of paths is being read and no wildcard substitution is desired.
-O output-file
--output-file output-file
Process the archive changes as usual, but instead of updating the existing archive, output the new archive to output-file. Useful for updating an archive without changing the existing archive and the input archive must be a different file than the output archive.

This option can be used to create updated split archives. It can also be used with -U to copy entries from an existing archive to a new archive. See the "Examples" section below.

Another use is converting zip files from one split size to another. For instance, to convert an archive with 700 MB CD splits to one with 2 GB DVD splits, you can use:

zip -s 2g --out

which uses copy mode. See -U below. Also:

zip -s 0 --out

will convert a split archive to a single-file archive.

Copy mode will convert stream entries (using data descriptors and which should be compatible with most unzips) to normal entries (which should be compatible with all unzips), except if standard encryption was used. For archives with encrypted entries, zipcloak will decrypt the entries and convert them to normal entries.

Set the "last modified" time on the zip file to match the "last modified" time on the zip archive entries.
-P password
--password 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.
Include relative file paths as part of the names of files stored in the archive. This is the default. The -j option junks the paths and just stores the names of the files.
Change to quiet mode by eliminating informational messages and command prompts.
Recurse into the directories starting at the current directory.
Recurse into the directories.
-s splitsize
--split-size splitsize
Enable creating a split archive and set the split size. A split archive is an archive that could be split over many files. As the archive is created, if the size of the archive reaches the specified split size, that split is closed and the next split opened. In general all splits but the last will be the split size and the last will be whatever is left. If the entire archive is smaller than the split size a single-file archive is created.

Split archives are stored in numbered files. For example, if the output archive is named archive and three splits are required, the resulting archive will be in the three files archive.z01, archive.z02, and Do not change the numbering of these files, or the archive will not be readable as these are used to determine the order the splits are read.

Split size is a number optionally followed by a multiplier. Currently the number must be an integer. The multiplier can currently be one of k (kilobytes), m (megabytes), g (gigabytes), or t (terabytes). As 64 KB is the minimum split size, numbers without multipliers default to megabytes. For example, to create a split archive called foo with the contents of the bar directory with splits of 670 MB that might be useful for burning on CDs, you could use this command:

zip -s 670m -r foo bar

Currently the old splits of a split archive are not excluded from a new archive, but they can be specifically excluded. If possible, keep the input and output archives out of the path being zipped when creating split archives.

Using -s without -sp as above creates all the splits where foo is being written, in this case the current directory. This split mode updates the splits as the archive is being created, requiring all splits to remain writable, but creates split archives that are readable by any unzip that supports split archives. See -sp below for enabling split pause mode, which allows splits to be written directly to removable media.

The option -sv can be used to enable verbose splitting and pro- vide details of how the splitting is being done. The -sb option can be used to ring the bell when zip pauses for the next split destination.

Split archives cannot be updated, but see the -O (--out) option for how a split archive can be updated as it is copied to a new archive. A split archive can also be converted into a single-file archive using a split size of 0 or negating the -s option:

zip -s 0 --out

Also see -U (--copy) for more on using copy mode.

If splitting and using split pause mode, ring the bell when zip pauses for each split destination.
Show the command line starting zip as processed, and then exit. The command parser permutes the arguments, putting all options and any values associated with them before any non-option arguments. This allows an option to appear anywhere in the command line as long as any values that go with the option go with it. This option displays the command line as zip sees it, including any arguments from the environment such as from the ZIPOPT variable. Where allowed, options later in the command line can override options earlier in the command line.
Show the files that would be operated on, and then exit. For instance, if creating a new archive, this will list the files that would be added. If the option is negated, -sf-, output only to an open log file. Screen display is not recommended for large lists.
Show all available options supported by zip as compiled on the current system. As this command reads the option table, it should include all options. Each line includes the short option (if defined), the long option (if defined), the format of any value that goes with the option, if the option can be negated, and a small description. The value format can be no value, required value, optional value, single character value, number value, or a list of values. The output of this option is not intended to show how to use any option but only show what options are available.
If splitting is enabled with -s, enable split pause mode. This creates split archives as -s does, but stream writing is used so each split can be closed as soon as it is written and zip will pause between each split to allow changing split destination or media.

Though this split mode allows writing splits directly to remov- able media, it uses stream archive format that may not be read- able by some unzips. Before relying on splits created with -sp, test a split archive with the unzip you will be using.

To convert a stream split archive (created with -sp) to a standard archive, see the --out option.

As -sf, but also show the Unicode version of the path if it exists.
As -sf, but only show the Unicode version of the path if it exists, otherwise show the standard version of the path.
Enable various verbose messages while splitting, showing how the splitting is being done.
Test the integrity of the new zip file. If the check fails, the old zip file is unchanged, and (with the -m option) no input files are removed.
-TT cmd
--unzip-command cmd
Use command cmd instead of unzip -tqq to test an archive when the -T option is used. On Unix, to use a copy of unzip in the current directory instead of the standard system unzip, you could use:
zip archive file1 file2 -T -TT "./unzip -tqq"

In cmd, {} is replaced by the name of the temporary archive, otherwise the name of the archive is appended to the end of the command. The return code is checked for success (0 on Unix).

-t mmddyyyy
--from-date 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
--before-date 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.
Copy entries from one archive to another. Requires the --out option to specify a different output file than the input archive. Copy mode is the reverse of -d delete. When delete is being used with --out, the selected entries are deleted from the archive and all other entries are copied to the new archive, while copy mode selects the files to include in the new archive. Unlike -u update, input patterns on the command line are matched against archive entries only and not the file system files. For instance:
zip inarchive "*.c" --copy --out outarchive

copies entries with names ending in .c from inarchive to outarchive. The wildcard must be escaped on some systems to prevent the shell from substituting names of files from the file system which may have no relevance to the entries in the archive.

If no input files appear on the command line and --out is used, copy mode is assumed:

zip inarchive --out outarchive

This is useful for changing split size for instance. Encrypting and decrypting entries is not yet supported using copy mode. Use zipcloak for that.

-UN v
--unicode v
Determine what zip should do with Unicode file names. Version 3.0 of zip, in addition to the standard file path, includes the UTF-8 translation of the path if the entry path is not entirely 7-bit ASCII. When an entry is missing the Unicode path, zip reverts back to the standard file path. The problem with using the standard path is this path is in the local character set of the zip that created the entry, which may contain characters that are not valid in the character set being used by the unzip. When zip is reading an archive, if an entry also has a Unicode path, zip now defaults to using the Unicode path to recreate the standard path using the current local character set.

This option can be used to determine what zip should do with this path if there is a mismatch between the stored standard path and the stored UTF-8 path (which can happen if the standard path was updated). In all cases, if there is a mismatch, it is assumed that the standard path is more current and zip uses that. Values for v are:

  • q — quit if paths do not match
  • w — warn, and then continue with standard path
  • i — ignore, and then continue with standard path
  • n — no Unicode; do not use Unicode paths

The default is to warn and continue.

Characters that are not valid in the current character set are escaped as #Uxxxx and #Lxxxxxx, where x is an ASCII character for a hex digit. The first is used if a 16-bit character number is sufficient to represent the Unicode character and the second if the character needs more than 16 bits to represent it's Unicode character code. Setting -UN to e (escape), as in:

zip archive -sU -UN=e

forces zip to escape all characters that are not printable 7-bit ASCII.

Normally zip stores UTF-8 directly in the standard path field on systems where UTF-8 is the current character set and stores the UTF-8 in the new extra fields otherwise. The option u (UTF-8), as in

zip archive dir -r -UN=UTF8

forces zip to store UTF-8 as native in the archive. Note that storing UTF-8 directly is the default on Unix systems that support it. This option could be useful on Windows systems where the escaped path is too large to be a valid path and the UTF-8 version of the path is smaller, but native UTF-8 is not backward compatible on Windows systems.

Update only changed or new files. The -u option with no input file arguments acts like the -f (freshen) option.
Be verbose, or print version information.
Wildcards match only at a directory level. Normally zip handles paths as strings, and given the paths /foo/bar/dir/file1.c and /foo/bar/file2.c, an input pattern such as /foo/bar/* normally would match both paths, the * matching dir/file1.c and file2.c. Note that in the first case a directory boundary (/) was crossed in the match. With -ws no directory bounds will be included in the match, making wildcards local to a specific directory level. So, with -ws enabled, only the second path would be matched.

When using -ws, use ** to match across directory boundaries as * does normally.

Don't save extra file attributes (Extended Attributes on OS/2, uid/gid and file times on Unix).
-x files
--exclude files
Explicitly exclude the files specified. For example:
zip -r foo foo -x \*.o

includes the contents of foo in, while it excludes all the files that end in .o.

Store symbolic links as links instead of as the referenced files.
-Z cm
--compression-method cm
Set the default compression method. Currently the main methods supported by zip are store and deflate. Compression method can be set to:
  • store — setting the compression method to store forces zip to store entries with no compression. This is generally faster than compressing entries, but results in no space savings. This is the same as using -0 (compression level zero).
  • deflate — this is the default method for zip. If zip determines that storing is better than deflation, the entry will be stored instead.
  • bzip2 — if bzip2 support is compiled in, this compression method also becomes available. Only some modern unzips currently support the bzip2 compression method, so test the unzip you will be using before relying on archives using this method (compression method 12). For example, to add bar.c to archive foo using bzip2 compression:
    zip -Z bzip2 foo bar.c

The compression method can be abbreviated:

zip -Zb foo bar.c
Prompt for a multiline comment for the entire zip archive. The comment is ended by a line containing just a period, or an end-of-file condition. The comment can be taken from a file:
zip -z foo < foowhat


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 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 and adds foo/file3 to Then, contains foo/file1, foo/file2, and foo/file3; foo/file2 remains unchanged.


Create an archive called, 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, 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 The first command creates the 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:

A set of default options for zip. For example:
export ZIPOPT="-D"

Exit status:

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

Contributing author: