last modified March 3, 2025
The zip command in Linux is used to compress and archive files and
directories. It creates .zip files, which are widely used for file
compression and sharing. This tutorial covers basic and advanced usage of
zip with practical examples.
zip is commonly used for reducing file size, combining multiple
files into a single archive, and encrypting archives for security.
This example demonstrates how to compress a single file.
zip archive.zip file.txt
The zip command creates archive.zip containing
file.txt.
This example shows how to compress multiple files into a single archive.
zip archive.zip file1.txt file2.txt
The zip command combines file1.txt and
file2.txt into archive.zip.
This example demonstrates how to compress an entire directory.
zip -r archive.zip mydir/
The -r option recursively includes all files and subdirectories
in mydir/.
This example shows how to exclude specific files from compression.
zip archive.zip mydir/ -x mydir/exclude.txt
The -x option excludes exclude.txt from the archive.
This example demonstrates how to create an encrypted zip archive.
zip -e secure.zip file.txt
The -e option prompts for a password to encrypt
secure.zip.
This example shows how to split a zip archive into smaller parts.
zip -s 10m -r archive.zip mydir/
The -s option splits archive.zip into 10MB parts.
This example demonstrates how to update an existing zip archive.
zip -u archive.zip newfile.txt
The -u option adds newfile.txt to
archive.zip if it is newer or missing.
This example shows how to list the contents of a zip archive.
unzip -l archive.zip
The -l option lists the files in archive.zip.
This example demonstrates how to extract a zip archive.
unzip archive.zip
The unzip command extracts all files from
archive.zip.
This example shows how to extract a zip archive to a specific directory.
unzip archive.zip -d /path/to/directory/
The -d option extracts files to the specified directory.
zip for compressing files and directories.-e to encrypt archives containing sensitive data.-s to split large archives for easier sharing.-u to keep archives up-to-date.
In this article, we have explored various examples of using the zip
command for compressing, encrypting, and managing archives, including advanced
features like splitting and updating archives.
My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.
List all Linux tutorials.