The zip command in Linux is used to compress files into a .zip archive. It can also be used to create compressed archives from multiple files and directories.
Basic Syntax:
zip [options] archive_name.zip file1 file2 …
Examples:
1. Compressing files:
zip archive.zip file1.txt file2.txt
This creates a archive.zip containing file1.txt and file2.txt.
2. Compressing a directory:
zip -r archive.zip directory_name
This compresses the entire directory_name into archive.zip recursively.
3. Adding files to an existing archive:
zip archive.zip file3.txt
This adds file3.txt to the existing archive.zip.
4. Excluding files:
zip -r archive.zip directory_name -x “*.log”
This excludes .log files from being added to the archive.zip.
5. Password protection:
zip -e archive.zip file1.txt file2.txt
This creates archive zip and prompts you for a password.