In Linux, zip
is categorized as a file compression and archiving utility. It is used to package multiple files and directories into a single compressed file, which typically has a .zip
extension. This helps in reducing the file size for storage or transfer, and also in grouping files for easier management.
The zip
command creates ZIP archives, while the unzip
command is used to extract files from these archives. The ZIP format is widely supported across different operating systems, making it a popular choice for file compression.
The main purpose of zip is to create a zip archive and add files to it. The following command creates target.zip and adds three .txt files to it:
zip target.zip foo.txt bar.txt baz.txt
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
The -r also adds hidden file (files whose name starts with a dot).
The content of a zip file can be shown with unzip and the command line option -l:
unzip -l dir.zip
-d 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