Cheat Sheet #day64 - unzip

Cheat Sheet #day64 - unzip

unzip Command Cheatsheet

The unzip command is used to extract files from a ZIP archive. It’s a commonly used utility for decompressing ZIP files in Unix-like systems. Here’s a quick reference guide:

Basic Syntax

unzip [OPTION]... ZIP_FILE

Common Options

  • -d DIR, --directory=DIR: Extract files to the specified directory.

      unzip archive.zip -d /path/to/destination/
    
  • -o, --overwrite: Overwrite existing files without prompting.

      unzip -o archive.zip
    
  • -n, --never-overwrite: Never overwrite existing files.

      unzip -n archive.zip
    
  • -q, --quiet: Suppress all output except errors.

      unzip -q archive.zip
    
  • -j, --junk-paths: Extract files without their directory structure.

      unzip -j archive.zip
    
  • -l, --list: List the contents of the ZIP file without extracting them.

      unzip -l archive.zip
    
  • -x FILE, --exclude=FILE: Exclude files matching the pattern.

      unzip archive.zip -x "*.bak"
    
  • -p, --stdout: Write files to standard output.

      unzip -p archive.zip file.txt > extracted.txt
    
  • -t, --test: Test the integrity of the ZIP file without extracting it.

      unzip -t archive.zip
    

Examples

  1. Extract all files to the current directory:

     unzip archive.zip
    
  2. Extract files to a specific directory:

     unzip archive.zip -d /path/to/destination/
    
  3. Overwrite existing files without prompting:

     unzip -o archive.zip
    
  4. Never overwrite existing files:

     unzip -n archive.zip
    
  5. Suppress all output except errors:

     unzip -q archive.zip
    
  6. Extract files without their directory structure:

     unzip -j archive.zip
    
  7. List contents of the ZIP file:

     unzip -l archive.zip
    
  8. Exclude specific files while extracting:

     unzip archive.zip -x "*.bak"
    
  9. Extract a file to standard output:

     unzip -p archive.zip file.txt > extracted.txt
    
  10. Test the integrity of the ZIP file:

    unzip -t archive.zip
    

Additional Information

  • Help option:

      unzip --help
    
  • View unzip manual page:

      man unzip
    

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

Did you find this article valuable?

Support Cloud Tuned by becoming a sponsor. Any amount is appreciated!