zip is a compression and file packaging utility.
A companion program unzip unpacks zip archives.
Large Archives and Zip64
zip automatically uses the Zip64 extensions when files larger than 4 GB are added to an archive, an archive containing Zip64 entries is updated (if the resulting archive still needs Zip64), the size of the archive will exceed 4 GB, or when the number of entries in the archive will exceed about 64K.
For a brief help on zip and unzip, run each without specifying any parameters on the command line.
Use
The program 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.
The zip program puts one or more compressed files into a single zip archive, along with information about the files (name, path, date, time of last modification, protection, and check information to verify file integrity). An entire directory structure can be packed into a zip archive with a single command. Compression ratios of 2:1 to 3:1 are common for text files. zip has one compression method (deflation) and can also store files without compression. zip automatically chooses the better of the two (deflation or store) for each file to be compressed.
Command format
The basic command format is
zip options archive inpath inpath ...
where archive is a new or existing zip archive and inpath is a directory or file path optionally including wildcards. When given the name of an existing zip archive, zip will replace identically named entries in the zip archive (matching the relative names as stored in the archive) or add 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.zip foo
or more concisely
zip -r foo foo
will replace foo/file1 in foo.zip and add foo/file3 to foo.zip. After this, foo.zip contains foo/file1, foo/file2, and foo/file3, with foo/file2 unchanged from before.
So if before the zip command is executed foo.zip has:
foo/file1 foo/file2
and directory foo has:
file1 file3
then foo.zip will have:
foo/file1 foo/file2 foo/file3
where foo/file1 is replaced and foo/file3 is new.
-@ file lists
If a file list is specified as -@, zip takes the list of input files from standard input instead of from the command line. For example,
zip -@ foo
will store the files listed one per line on stdin in foo.zip.
This option can be used to powerful effect in conjunction with the find command. For example, to archive all the C source files in the current directory and its subdirectories:
find . -name "*.[ch]" -print | zip source -@
(note that the pattern must be quoted to keep the shell from expanding it).
Streaming input and output
zip will also accept a single dash ("-") as the zip file name, in which case it will write the zip file to standard output, allowing the output to be piped to another program. For example:
zip -r - . | (ftyp binary ; bs2cp -f - bs2:foo.zip)
would write the zip output directly to a BS2000 file.
zip also accepts a single dash ("-") as the name of a file to be compressed, in which case it will read the file from standard input, allowing zip to take input from another program. For example:
tar cf - . | zip backup -
would compress the output of the tar command for the purpose of backing up the current directory. This generally produces better compression than the previous example using the -r option because zip can take advantage of redundancy between files. The backup can be restored using the command
unzip -p backup | tar xf -
When no zip file name is given and stdout is not a terminal, zip acts as a filter, compressing standard input to standard output. For example,
tar cf - . | zip | (ftyp binary ; bs2cp -f - bs2:foo.zip)
is equivalent to
tar cf - . | zip - - | (ftyp binary ; bs2cp -f - bs2:foo.zip)
zip archives created in this manner can be extracted with the program funzip which is provided in the unzip package. For example:
ftyp binary; bs2cp bs2:foo.zip - | funzip | tar xvf -
The stream can also be saved to a file and unzip used.
When directing the output to another file, note that all options should be before the redirection including -x. For example:
zip archive "*.h" "*.c" -x donotinclude.h orthis.h > tofile
Zip files
When changing an existing zip archive, zip will write a temporary file with the new contents, and only replace the old one when the process of creating the new version has been completed without error.
If the name of the zip archive does not contain an extension, the extension .zip is added. If the name already contains an extension other than .zip, the existing extension is kept unchanged. However, split archives (archives split over multiple files) require the .zip extension on the last split.
Scanning and reading files.
When zip starts, it scans for files to process (if needed). If this scan takes longer than about 5 seconds, zip will display a "Scanning files" message.
Command modes
zip now supports two distinct types of command modes, external and internal. The external modes (add, update, and freshen) read files from the file system (as well as from an existing archive) while the internal modes (delete and copy) operate exclusively on entries in an existing archive.
add
Update existing entries and add new files. If the archive does not exist create it. This is the default mode.
update (-u)
Update existing entries if newer on the file system and add new files. If the archive does not exist issue warning then create a new archive.
freshen (-f)
Update existing entries of an archive if newer on the file system. Does not add new files to the archive.
delete (-d)
Select entries in an existing archive and delete them.
copy (-U)
Select entries in an existing archive and copy them to a new archive. This new mode is similar to update but command line patterns select entries in the existing archive rather than files from the file system and it uses the --out option to write the resulting archive to a new file rather than update the existing archive, leaving the original archive unchanged.
The new File Sync option (-FS) is also considered a new mode, though it is similar to update. This mode synchronizes the archive with the files on the OS, only replacing files in the archive if the file time or size of the OS file is different, adding new files, and deleting entries from the archive where there is no matching file. As this mode can delete entries from the archive, consider making a backup copy of the archive.
Also see -DF for creating difference archives.
See each option description below for details and the section "Examples".
Split archives
zip version 3.0 and later can create split archives.
A split archive is a standard zip archive split over multiple files. (Note that split archives are not just archives split in to pieces, as the offsets of entries are now based on the start of each split. Concatenating the pieces together will invalidate these offsets, but unzip can usually deal with it. zip will usually refuse to process such a spliced archive unless the -FF fix option is used to fix the offsets.)
One use of split archives is storing a large archive on multiple removable media. For a split archive with 20 split files the files are typically named (replace ARCHIVE with the name of your archive) ARCHIVE.z01, ARCHIVE.z02, ..., ARCHIVE.z19, ARCHIVE.zip. Note that the last file is the .zip file. In contrast, spanned archives are the original multi-disk archive generally requiring floppy disks and using volume labels to store disk numbers. zip supports split archives but not spanned archives, though a procedure exists for converting split archives of the right size to spanned archives. The reverse is also true, where each file of a spanned archive can be copied in order to files with the above names to create a split archive.
Use -s to set the split size and create a split archive. The size is given as a number followed optionally by one of k (kB), m (MB), g (GB), or t (TB) (the default is m). The -sp option can be used to pause zip between splits to allow changing removable media, for example, but read the descriptions and warnings for both -s and -sp below.
Though zip does not update split archives, zip provides the new option -O (--output-file or --out) to allow split archives to be updated and saved in a new archive. For example,
zip inarchive.zip foo.c bar.c --out outarchive.zip
reads archive inarchive.zip, even if split, adds the files foo.c and bar.c, and writes the resulting archive to outarchive.zip. If inarchive.zip is split then outarchive.zip defaults to the same split size. Be aware that if outarchive.zip and any split files that are created with it already exist, these are always overwritten as needed without warning. This may be changed in the future.
Command line format
This version of zip has updated command line processing and support for long options.
Short options take the form
-s[-][s[-]...][value][=value][ value]
where s is a one or two character short option. A short option that takes a value is last in an argument and anything after it is taken as the value. If the option can be negated and "-" immediately follows the option, the option is negated. Short options can also be given as separate arguments
-s[-][value][=value][ value] -s[-][value][=value][ value] ...
Short options in general take values either as part of the same argument or as the following argument. An optional = is also supported.
So
-ttmmddyyyy
and
-tt=mmddyyyy
and
-tt mmddyyyy
all work. The -x and -i options accept lists of values and use a slightly different format described below. See the -x and -i options.
Long options take the form
--longoption[-][=value][ value]
where the option starts with --, has a multicharacter name, can include a trailing dash to negate the option (if the option supports it), and can have a value (option argument) specified by preceeding it with = (no spaces). Values can also follow the argument. So
--before-date=mmddyyyy
and
--before-date mmddyyyy
both work.
Long option names can be shortened to the shortest unique abbreviation.
See the option descriptions below for which support long options.
To avoid confusion, avoid abbreviating a negatable option with an embedded dash ("-") at the dash if you plan to negate it (the parser would consider a trailing dash, such as for the option --some-option using --some- as the option, as part of the name rather than a negating dash). This may be changed to force the last dash in --some- to be negating in the future.
Syntax
zip [-option ...] [--longoption ...] [-b path] [-ds size] [-n suffixes] [-O outputfile] [-P password] [-s splitsize] [-t date] [-tt date] [zipfile [file ...]] [-i files] [-x files] |
Note: Command line processing in zip has been changed to support long options and handle all options and arguments more consistently. Some old command lines that depend on command line inconsistencies may no longer work.
Translate file to ASCII format.
Adjust 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.
Use the specified path for the temporary zip archive.
will put the temporary zip archive in the directory /tmp, copying over stuff.zip to the current directory when done. This option is useful when updating an existing archive and the file system containing this old archive does not have enough space to hold both old and new archives at the same time. It may also be useful when streaming in some cases to avoid the need for data descriptors. Note that using this option may require zip take additional time to copy the archive file when done to the destination file system.
Add one-line comments for each file. File operations (adding, updating) are done first, and the user is then prompted for a one-line comment for each file. Enter the comment followed by return, or just return for no comment.
Remove (delete) entries from a zip archive.
will remove the entry foo/tom/junk, all of the files that start with foo/harry/, and all of the files that end with .o (in any path). Note that shell pathname expansion has been inhibited with backslashes, so that zip can see the asterisks, enabling zip to match on the contents of the zip archive instead of the contents of the current directory. Can also use quotes to escape the asterisks as in
Not escaping the asterisks on a system could result in the asterisks being converted to a list of files in the current directory and that list used to delete entries from the archive.
Display running byte counts showing the bytes zipped and the bytes to go.
Display running count of entries zipped and entries to go.
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.
Do not create entries in the zip archive for directories.
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.
from the bar directory, then the command
also from the bar directory creates the archive foonew with just the files not in foofull and the files where the size or file time of the files do not match those in foofull. 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.
Encrypt the contents of the zip archive using a password which is entered on the terminal in response to a prompt (this will not be echoed; if standard error is not a tty, zip will exit with an error). The password prompt is repeated to save the user from typing errors.
Replace (freshen) an existing entry in the zip archive only if it has been modified more recently than the version already in the zip archive; unlike the update option (-u) this will not add files that are not already in the zip archive.
This command should be run from the same directory from which the original zip command was run, since paths stored in zip archives are always relative. Note that the timezone environment variable TZ should be set according to the local timezone in order for the -f, -u and -o options to work correctly.
Fix the zip archive. The -F option can be used if some portions of the archive are missing, but requires a reasonably intact central directory. The input archive is scanned as usual, but zip will ignore some problems. The resulting archive should be valid, but any inconsistent entries will be left out. When doubled as in -FF, the archive is scanned from the beginning and zip scans for special signatures to identify the limits between the archive members. The single -F is more reliable if the archive is not too much damaged, so try this option first. If the archive is too damaged or the end has been truncated, you must use -FF. Neither option will recover archives that have been incorrectly transferred in ascii mode instead of binary. After the repair, the -t option of unzip may show that some files have a bad CRC. Such files cannot be recovered; you can remove them from the archive using the -d option of zip. Note that -FF may have trouble fixing archives that include an embedded zip archive that was stored (without compression) in the archive and, depending on the damage, it may find the entries in the embedded archive rather than the archive itself. Try -F first as it does not have this problem. For example, to fix the damaged archive foo.zip,
tries to read the entries normally, copying good entries to the new archive foofix.zip. If this doesn’t work, as when the archive is truncated, or if some entries you know are in the archive are missed, then try
and compare the resulting archive to the archive created by -F. The -FF option may create an inconsistent archive. Depending on what is damaged, you can then use the -F option to fix that archive. A split archive with missing split files can be fixed using -F if you have the last split of the archive (the .zip file). If this file is missing, you must use -FF to fix the archive, which will prompt you for the splits you have. Currently the fix options can’t recover entries that have a bad checksum or are otherwise damaged.
Normally zip skips reading any FIFOs (named pipes) encountered, as zip can hang if the FIFO is not 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 new 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.
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 the zip help information (this also appears if zip is run with no arguments).
Display extended help including more on command line format, pattern matching, and more options.
Include only the specified files, as in:
which will include only the files that end in .c in the current directory and its subdirectories. So to include dir, a directory directly under the current directory, use
or
to match paths such as dir/a and dir/b/file.c Note that currently the trailing / is needed for directories, as in
to include directory dir. The long option form of the first example is
and does the same thing as the short option form. The list of files terminates at the next argument starting with -, the end of the command line, or the list terminator @ (an argument that is just @). So the above can be given as
for example. There must be a space between the option and the first file of a list. For just one file you can use the single value form
(no space between option and value) or
as additional examples. Use -sc to see how your command line will be parsed. Also possible:
which will only include the files in the current directory and its subdirectories that match the patterns in the file include.lst. Files to -i and -x are patterns matching internal archive paths. See -R for more on patterns.
Store just the name of a saved file (junk the path), and do not store directory names. By default, zip will store the full path (relative to the current directory).
Strip any prepended data (e.g. a SFX stub) from the archive.
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.
Translate the Unix end-of-line character LF into the MSDOS convention CR LF. This option should not be used on binary files. This option can be used if the zip file is intended for PKUNZIP under MSDOS. If the input files already contain CR LF, this option adds an extra CR. This is to ensure that
Append to existing logfile. Default is to overwrite.
Open a logfile at the given path. By default any existing file at that location is overwritten, but the -la option will result in an existing file being 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. If -ll detects binary in the first buffer read from a file, zip issues a warning and skips line end conversion on the file.
Display the zip license.
Move the specified files into the zip archive; actually, this deletes the target directories/files after making the specified zip archive. 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 it is recommended to use it in combination with -T to test the archive before removing all input files.
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) instead of the normal success return (0). 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.
Do not attempt to compress files named with the given suffixes. Such files are simply stored (0% compression) in the output zip file, so that zip doesn’t waste its time trying to compress them. The suffixes are separated by either colons or semicolons. For example:
will copy everything from foo into foo.zip, but will store any files that end in .Z, .zip, .tiff, .gif, or .snd without trying to compress them (image and sound files often have their own specialized compression methods). By default, zip does not compress files with extensions in the list .Z:.zip:.zoo:.arc:.lzh:.arj. Such files are stored directly in the output archive. The environment variable ZIPOPT can be used to change the default options. To attempt compression on all files, use:
The maximum compression option -9 also attempts compression on all files regardless of extension.
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.
Set the "last modified" time of the zip archive to the latest (oldest) "last modified" time found among the entries in the zip archive. This can be used without any other operations, if desired. For example:
will change the last modified time of foo.zip to the latest time of the entries in foo.zip.
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 section "Examples" ). 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, can use:
which uses copy mode. See -U below. Also:
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.
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.
Use password to encrypt zipfile entries (if any). THIS IS INSECURE! Where security is truly important, use strong encryption instead of the relatively weak standard encryption provided by zipfile utilities.
Quiet mode; eliminate informational messages and comment prompts. (Useful, for example, in shell scripts and background tasks).
Travel the directory structure recursively; for example:
or more concisely
In this case, all the files and directories in foo are saved in a zip archive named foo.zip, including files with names starting with ".", since the recursion does not use the shell’s file-name substitution mechanism. If you wish to include only a specific subset of the files in directory foo and its subdirectories, use the -i option to specify the pattern of files to be included. You should not use -r with the name ".*", since that matches ".." which will attempt to zip up the parent directory (probably not what was intended). Multiple source directories are allowed as in
which first zips up foo1 and then foo2, going down each directory.
Travel the directory structure recursively starting at the current directory; for example:
In this case, all the files matching *.c in the tree starting at the current directory are stored into a zip archive named foo.zip. Note that *.c will match file.c, a/file.c and a/b/.c. More than one pattern can be listed as separate arguments.
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 archive.zip. 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. The number must be an integer. The multiplier can be one of k (kilobytes), m (megabytes), g (gigabytes), or t (terabytes). As 64k is the minimum split size, numbers without multipliers default to megabytes. 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:
Also see -U (--copy) for more on using copy mode.
Show the command line starting zip as processed and 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, 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 removable media, it uses stream archive format that may not be readable 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.
Enable various verbose messages while splitting, showing how the splitting is being done.
Do not operate on files modified prior to the specified date, where mm is the month (01-12), dd is the day of the month (01-31), and yyyy is the year. The ISO 8601 date format yyyy-mm-dd is also accepted. For example:
will add all the files in foo and its subdirectories that were last modified on or after 7 December 1991, to the zip archive infamy.zip.
Do not operate on files modified after or at the specified date, where mm is the month (01-12), dd is the day of the month (01-31), and yyyy is the year. The ISO 8601 date format yyyy-mm-dd is also accepted. For example:
will add all the files in foo and its subdirectories that were last modified before 30 November 1995, to the zip archive infamy.zip.
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.
Use command cmd instead of "
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.
Replace (update) an existing entry in the zip archive only if it has been modified more recently than the version already in the zip archive. For example:
will add any new files in the current directory, and update any files which have been modified since the zip archive stuff.zip was last created/modified (note that zip will not try to pack stuff.zip into itself when you do this). Note that the -u option with no input file arguments acts like the -f (freshen) option.
Copy entries from one archive to another. Requires the --output-file 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 --output-file, 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 copies entries with names ending in .c from inarchive to outarchive. If no input files appear on the command line and --out is used, copy mode is assumed:
This is useful for changing split size for instance. Encrypting and decrypting entries is not yet supported using copy mode. Use zipcloak for that.
Verbose mode or print diagnostic version info. Normally, when applied to real operations, this option enables the display of a progress indicator during compression and requests verbose diagnostic info about zipfile structure oddities. However, when -v is the only command line argument a diagnostic screen is printed instead.
Wildcards match only at a directory level. Normally zip handles paths as strings and given the paths
an input pattern such as
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.
Explicitly exclude the specified files, as in:
which will include the contents of foo in foo.zip while excluding all the files that end in .o. The backslash avoids the shell filename substitution, so that the name matching is performed by zip at all directory levels. Also possible:
which will include the contents of foo in foo.zip while excluding all the files that match the patterns in the file exclude.lst. The long option forms of the above are
and
Multiple patterns can be specified, as in:
If there is no space between -x and the pattern, just one value is assumed (no list):
See -i for more on include and exclude.
Do not save extra file attributes (uid/gid and file times). The zip format uses extra fields to include additional information for each entry. Some extra fields are specific to particular systems while others are applicable to all systems. Normally when zip reads entries from an existing archive, it reads the extra fields it knows, strips the rest, and adds the extra fields applicable to that system. With -X, zip strips all old fields and only includes the Zip64 extra fields. Negating this option, -X-, includes all the default extra fields, but also copies over any unrecognized extra fields.
Store symbolic links as such in the zip archive, instead of compressing and storing the file referred to by the link. This can avoid multiple copies of files being included in the archive as zip recurses the directory trees and accesses files directly and by links.
Prompt for a multi-line comment for the entire zip archive. The comment is ended by a line containing just a period, or an end of file condition (Ctrl-D). The comment can be taken from a file:
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. For example, to add bar.c to archive foo using store compression:
The compression method can be abbreviated:
( Regulate the speed of compression using the specified digit #, where -0 indicates no compression (store all files), -1 indicates the fastest compression speed (less compression) and -9 indicates the slowest compression speed (optimal compression, ignores the suffix list). The default compression level is -6.
Take the list of input files from standard input. Only one filename per line. |
Examples
The simplest example:
creates the archive stuff.zip (assuming it does not exist) and puts all the files in the current directory in it, in compressed form (the .zip suffix is added automatically, unless the archive name contains a dot already; this allows the explicit specification of other suffixes). Files starting with "." are not included; to include these as well:
Even this will not include any subdirectories from the current directory. To zip up an entire directory, the command:
creates the archive foo.zip, containing all the files and directories in the directory foo that is 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. You can use the -j option to leave off the paths, as in:
If you are 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. If foo contains the subdirectories tom, dick, and harry, you can:
where the first command creates foo.zip, and the next two add to it. At the completion of each zip command, the last created archive is deleted, making room for the next zip command to function. Use -s to set the split size and create a split archive. The size is given as a number followed optionally by one of k (kB), m (MB), g (GB), or t (TB). The command
creates a split archive of the directory foo with splits no bigger than 2 GB each. If foo contained 5 GB of contents and the contents were stored in the split archive without compression (to make this example simple), this would create three splits, split.z01 at 2 GB, split.z02 at 2 GB, and split.zip at a little over 1 GB. The -sp option can be used to pause zip between splits to allow changing removable media, for example, but read the descriptions and warnings for both -s and -sp below. Though zip does not update split archives, zip provides the option -O (--output-file) to allow split archives to be updated and saved in a new archive. For example,
reads archive inarchive.zip, even if split, adds the files foo.c and bar.c, and writes the resulting archive to outarchive.zip. If inarchive.zip is split then outarchive.zip defaults to the same split size. Be aware that outarchive.zip and any split files that are created with it are always overwritten without warning. This may be changed in the future. |
Pattern matching
The shell does filename substitution on command arguments. Generally the special characters are:
match any single character
match any number of characters (including none)
match any character in the range indicated within the brackets (example: [a-f], [0-9]). This form of wildcard matching allows a user to specify a list of characters between square brackets and if any of the characters match the expression matches. When these characters are encountered (without being escaped with a backslash or quotes), the shell will look for files relative to the current path that match the pattern, and replace the argument with a list of the names that matched. The zip program can do the same matching on names that are in the zip archive being modified or, in the case of the -x (exclude) or -i (include) options, on the list of files to be operated on, by using backslashes or quotes to tell the shell not to do the name expansion. In general, when zip encounters a name in the list of files to do, it first looks for the name in the file system. If it finds it, it then adds it to the list of files to do. If it does not find it, it looks for the name in the zip archive being modified (if it exists), using the pattern matching characters described above, if present. For each match, it will add that name to the list of files to be processed, unless this name matches one given with the -x option, or does not match any name given with the -i option. The pattern matching includes the path, and so patterns like \*.o match names that end in ".o", no matter what the path prefix is. Note that the backslash must precede every special character (i.e. ?*[]), or the entire argument must be enclosed in double quotes (""). In general, use backslashes or double quotes for paths that have wildcards to make zip do the pattern matching for file paths, and always for paths and strings that have spaces or wildcards for -i, -x, -R, -d, and -U and anywhere zip needs to process the wildcards. |
Variable
The following environment variables are read and used by zip as described. ZIPOPT contains default options that will be used when running zip. The contents of this environment variable will get added to the command line just after the zip command. ZIP alternative default options variable (if ZIPOPT is empty or does not exist). |
Exit status
The exit status (or error level) approximates the exit codes defined by PKWARE and takes on the following values: | |
0 | normal; no errors or warnings detected. |
2 | unexpected end of zip file. |
3 | a generic error in the zipfile format was detected. Pro cessing may have completed successfully anyway; some broken zipfiles created by other archivers have simple workarounds. |
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 processed or 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 control-C (or similar). |
10 | zip encountered an error while using a temp 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. |
19 | zip was compiled with options not supported on this system. |
See also
compress, unzip |