# 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

```sh
unzip [OPTION]... ZIP_FILE
```

#### Common Options

* `-d DIR`, `--directory=DIR`: Extract files to the specified directory.
    
    ```sh
    unzip archive.zip -d /path/to/destination/
    ```
    
* `-o`, `--overwrite`: Overwrite existing files without prompting.
    
    ```sh
    unzip -o archive.zip
    ```
    
* `-n`, `--never-overwrite`: Never overwrite existing files.
    
    ```sh
    unzip -n archive.zip
    ```
    
* `-q`, `--quiet`: Suppress all output except errors.
    
    ```sh
    unzip -q archive.zip
    ```
    
* `-j`, `--junk-paths`: Extract files without their directory structure.
    
    ```sh
    unzip -j archive.zip
    ```
    
* `-l`, `--list`: List the contents of the ZIP file without extracting them.
    
    ```sh
    unzip -l archive.zip
    ```
    
* `-x FILE`, `--exclude=FILE`: Exclude files matching the pattern.
    
    ```sh
    unzip archive.zip -x "*.bak"
    ```
    
* `-p`, `--stdout`: Write files to standard output.
    
    ```sh
    unzip -p archive.zip file.txt > extracted.txt
    ```
    
* `-t`, `--test`: Test the integrity of the ZIP file without extracting it.
    
    ```sh
    unzip -t archive.zip
    ```
    

#### Examples

1. **Extract all files to the current directory:**
    
    ```sh
    unzip archive.zip
    ```
    
2. **Extract files to a specific directory:**
    
    ```sh
    unzip archive.zip -d /path/to/destination/
    ```
    
3. **Overwrite existing files without prompting:**
    
    ```sh
    unzip -o archive.zip
    ```
    
4. **Never overwrite existing files:**
    
    ```sh
    unzip -n archive.zip
    ```
    
5. **Suppress all output except errors:**
    
    ```sh
    unzip -q archive.zip
    ```
    
6. **Extract files without their directory structure:**
    
    ```sh
    unzip -j archive.zip
    ```
    
7. **List contents of the ZIP file:**
    
    ```sh
    unzip -l archive.zip
    ```
    
8. **Exclude specific files while extracting:**
    
    ```sh
    unzip archive.zip -x "*.bak"
    ```
    
9. **Extract a file to standard output:**
    
    ```sh
    unzip -p archive.zip file.txt > extracted.txt
    ```
    
10. **Test the integrity of the ZIP file:**
    
    ```sh
    unzip -t archive.zip
    ```
    

#### Additional Information

* **Help option:**
    
    ```sh
    unzip --help
    ```
    
* **View** `unzip` manual page:
    
    ```sh
    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`.
