zip Linux Command
Creates a compressed ZIP archive of files and directories.
What does zip do?
Creates a compressed ZIP archive of files and directories.
Syntax
zip [options] archive.zip filesPractical example
zip -r project.zip ./myprojectQuestions about zip
How do I create a zip archive?
Use `zip archive.zip file1 file2` to create a zip archive containing the specified files.
How do I zip a directory recursively?
Use `zip -r archive.zip directory/` to include all files and subdirectories. The `-r` flag is essential for directories.
How do I extract a zip file?
Use `unzip archive.zip` to extract. Use `unzip archive.zip -d /path/` to extract to a specific directory.
How do I add files to an existing zip?
Use `zip archive.zip newfile.txt` to add new files to an existing zip archive.
How do I list contents of a zip file?
Use `unzip -l archive.zip` to list all files in the zip without extracting.
How do I exclude files from a zip?
Use `zip -r archive.zip directory/ -x '*.log'` to exclude files matching a pattern.
How do I encrypt a zip file?
Use `zip -e -r archive.zip directory/` to create a password-protected zip. You will be prompted for a password.
How do I test a zip file for errors?
Use `unzip -t archive.zip` to test the integrity of the zip file without extracting.
Related Compression Commands
bunzip2Decompresses a .bz2 file back to its original form.
unzipExtracts files from a ZIP archive.
bzip2Compresses files using the bzip2 algorithm (better compression than gzip, slower).
xzCompresses files using the xz (LZMA2) algorithm — very high compression ratio.
gunzipDecompresses a .gz file back to its original form.
unxzDecompresses a .xz file back to its original form.