zip

file_compressionlinux
The zip command is one of the most frequently used commands in Linux/Unix-like operating systems. zip Package and compress (archive) files

Quick Reference

Command Name:

zip

Category:

file_compression

Platform:

linux

Basic Usage:

zip [options] [arguments]

Common Use Cases

    Syntax

    zip [options] zipfile files...

    Options

    ## Common Options | Option | Description | |--------|-------------| | -r | Recursively include files in directories | | -e | Encrypt the contents of the zip file using a password | | -u | Update existing entries if newer on the filesystem | | -m | Move files into the zip archive (delete original files) | | -j | Store just the file name (junk the path) | | -0..9 | Set compression level (0=none, 9=maximum) | | -q | Quiet mode (suppress normal messages) | | -v | Verbose mode (show more information) | | -l | Convert LF to CR LF (useful for creating zips for Windows) | | -x | Exclude specified files from being added to the zip file | | -i | Include only the specified files | | -b | Specify path to use for temporary zip file | | -@ | Read the list of files to be processed from stdin | | -s | Create split archives (specify size e.g., -s 2g for 2GB) | | -sf | Show files in the zip archive | | -d | Delete entries from the zip file | | -t | Test the integrity of the zip file | | -z | Add a comment to the zip file | | -n | Don't compress files with specified suffixes | | -h | Display help information | | -y | Store symbolic links as links rather than the file referenced | | -k | Attempt to convert names and paths to be compatible with MS-DOS |

    Examples

    How to Use These Examples

    The examples below show common ways to use the zip command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    # Compress a file zip archive.zip file.txt
    # Compress multiple files zip archive.zip file1.txt file2.txt file3.txt
    # Compress all files in the current directory zip archive.zip *
    # Compress a directory and its contents zip -r archive.zip directory/
    # Advanced Examples Advanced
    # Create a password-protected zip archive zip -e secure.zip confidential.txt # Set compression level (0-9, 9 is highest) zip -9 highly_compressed.zip large_file.txt # Add files to an existing zip archive zip -u archive.zip newfile.txt # Exclude certain files while zipping a directory zip -r archive.zip directory/ -x "*.log" "*.tmp" # Create a split zip archive (limit size to 1GB per file) zip -s 1g large_archive.zip huge_file.dat # Display zip file contents without extracting zip -sf archive.zip # Add all .txt files from current directory and all subdirectories zip -r archive.zip . -i "*.txt" # Create a zip file without compression (just store) zip -0 archive.zip raw_files/*

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    ## Important Notes - Unlike gzip, zip doesn't remove the original files by default after compression. - The zip format is compatible across different operating systems (Linux, Windows, macOS). - The maximum file size that can be stored in a standard zip archive is 4GB. - For large files or better compression, consider using other formats like 7z. - For secure encryption, modern alternatives like AES-encrypted zip files or GPG are recommended. - Zip preserves file permissions on Unix/Linux systems with the -X option. - Zip can handle Unicode filenames, but there might be compatibility issues with older unzip programs. - Creating self-extracting zip archives requires additional tools. - While zip is available on most Linux distributions, it may need to be installed separately. ## Related Utilities - unzip: Extracts files from zip archives - zipcloak: Encrypts entries in a zipfile - zipnote: Reads or writes comments in a zipfile - zipsplit: Splits a zipfile into smaller zipfiles

    Related Commands

    These commands are frequently used alongside zip or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the zip command works in different scenarios.

    $ zip
    View All Commands