Zip

From LQWiki
Jump to navigation Jump to search

Zip archives and compresses files using a format compatible with PKZIP and WinZip. Unlike Linux or UNIX compression and archiving utilities, zip combines archiving and compression.

For options, see the man page. zip keeps original files intact ( except for very particular options ). To decompress files use unzip.

Usecases

  • You want to pack a folder source including all files. The archive shall be named target.zip
zip -r target source

Examples

  • zip -r myarchive myfolder
    Creates myarchive.zip, an archive containing every files and directories present in myfolder, even files with a starting dot.
  • zip documents *
    Creates the documents.zip archive containing all the files in the current directory. Files beginning with a dot might be excluded depending on your shell filename expansion feature configuration. Directories will be empty in documents.zip.
  • zip documents *.sdw
    Creates the documents.zip archive containing all the .sdw files present in the current directory.
  • zip -r archive * -x \*.doc
    Archives all files and directories in the working directory excluding names with the .doc suffix. Please note the backslashed "*" character to prevent the shell from interpreting it. It will be interpreted and applied by the zip command instead, in all processed directories.
  • zip -g documents essays/*
    Appends all the files of the essays directory to the existing documents.zip archive.
  • zip -mT documents *
    Moves all files of the current directory to the documents.zip archive. This is dangerous as this actually deletes those files. Please read the man page for more details.

TroubleShooting

  • You get the error message
zip warning: name not matched
This can mean your file is bigger than 2 GigaByte and cannot be packed therefore.
  • You get the error message
zip I/O error: Invalid argument
This can mean your file is bigger than 2 GigaByte and cannot be packed therefore.

See also