Search notes:

Create zip archives on the shell

zip is a shell command to create zip archive files.
zip options archive_name file file …

Creating a zip archive

The main purpose of zip is to create a zip archive (if it doesn't exist) and add or replace files to/in it. The following command creates target.zip and adds three .txt files to it:
zip target.zip foo.txt bar.txt baz.txt
Github repository shell-commands, path: /zip/add-files.sh

Creating a zip archive from a directory

The command line option -r adds files recursively. Thus, it allows to create a zip file from an entire (sub-)directory:
zip dir.zip -r dir
Github repository shell-commands, path: /zip/add-directory.sh
The -r also adds hidden file (files whose name starts with a dot).

Showing a zip files' content

With unzip, the content of a zip file can be shown with the command line option -l:
unzip -l dir.zip
Github repository shell-commands, path: /zip/show-content.sh

Unzipping into a specific directory

The -d option of unzip allows to specify a directory into which the contents of a zip file should be extracted.
The following command extracts dir.zip into the directory /tmp (and creates /tmp/dir):
unzip dir.zip -d /tmp
Github repository shell-commands, path: /zip/unzip-into-dir.sh

Don't add full path

With -j (junk directory names), the path from the root to the «top leve directory» of the files will be ommited
$ zip -j archive.zip /path/to/a/directory/I/dont/want/to/see/in/the/archive

List of options

-f freshen: update existing files only with changed files (i. e. don't add new files)
-d delete entries in zipfile
-r recurse into directories. Compare with -R
-0 store only
-1 compress faster
-q quiet operation. Compare with -v
-c Prompt for one-line comments for each entry. Compare with -z
-@ read names from stdin
-x exclude the following names
-F fix zipfile (-FF try harder)
-FS filesync: update if date or size changed, delete if no OS match
-A adjust self-extracting exe
-T test zipfile integrity
-y store symbolic links as the link instead of the referenced file
-e encrypt
-u update: only changed or new files
-m move file into zipfile (i.e. delete files from file system after operation)
-j junk (don't record) directory names
-l convert LF to CR LF (-ll CR LF to LF)
-9 compress better
-v verbose operation/print version info. Compare with -q
-z Parmopt for comment for zipfile comment. Compare with -c
-o make zipfile as old as latest entry
-i include only the following names
-D do not add directory entries
-J junk zipfile prefix (unzipsfx)
-X eXclude eXtra file attributes
-n don't compress these suffixes
-t, -tt Date filtering: exclude, include files modified after date, before date (date format mmddyyyy or yyyy-mm-dd)
Use -h2 to display more options.

See also

gzip, unzip
Shell commands
Perl modules IO::Compress::Gzip, IO::Uncompress::Gunzip, Archive::Zip and Archive::Extract
The Windows unzipper expand.exe

Index