Cheat Sheet #day63 - zip

Cloud TunedCloud Tuned
2 min read

zip Command Cheatsheet

The zip command is used to compress files into a ZIP archive. It is a popular utility for archiving and compressing files in Unix-like systems. Here’s a quick reference guide:

Basic Syntax

zip [OPTION]... ZIP_FILE FILE...

Common Options

  • -r, --recurse-paths: Recursively include directories and their contents.

      zip -r archive.zip directory/
    
  • -e, --encrypt: Encrypt the archive with a password.

      zip -e archive.zip file.txt
    
  • -9, --best: Use the best compression method.

      zip -9 archive.zip file.txt
    
  • -0, --store: Store files without compression.

      zip -0 archive.zip file.txt
    
  • -q, --quiet: Suppress all output except errors.

      zip -q archive.zip file.txt
    
  • -x, --exclude: Exclude files matching the pattern.

      zip -r archive.zip * -x "*.bak"
    
  • -j, --junk-paths: Do not store the full pathnames.

      zip -j archive.zip directory/*
    
  • -d, --delete: Delete files from the archive.

      zip -d archive.zip file.txt
    
  • -l, --local: Store symbolic links as symbolic links.

      zip -l archive.zip link.txt
    

Examples

  1. Create a ZIP archive with files:

     zip archive.zip file1.txt file2.txt
    
  2. Compress a directory recursively:

     zip -r archive.zip directory/
    
  3. Encrypt an archive with a password:

     zip -e archive.zip file.txt
    
  4. Use maximum compression:

     zip -9 archive.zip file.txt
    
  5. Store files without compression:

     zip -0 archive.zip file.txt
    
  6. Suppress output except errors:

     zip -q archive.zip file.txt
    
  7. Exclude files matching a pattern:

     zip -r archive.zip * -x "*.bak"
    
  8. Store files without full pathnames:

     zip -j archive.zip directory/*
    
  9. Delete a file from an archive:

     zip -d archive.zip file.txt
    
  10. Store symbolic links as links:

    zip -l archive.zip link.txt
    

Additional Information

  • Help option:

      zip --help
    
  • View zip manual page:

      man zip
    

This cheatsheet covers the essential options and usage scenarios for the zip command. For more detailed information, refer to the man page or use zip --help.

0
Subscribe to my newsletter

Read articles from Cloud Tuned directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Cloud Tuned
Cloud Tuned